driver core: Constify core device attributes

To make sure these attributes are not modified by accident or by an
attacker, move them to read-only memory.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://patch.msgid.link/20260512-sysfs-const-attr-device_attr-prep-v3-5-cb7c17b34d52@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Thomas Weißschuh 2026-05-12 18:39:15 +02:00 committed by Greg Kroah-Hartman
parent 434506b86a
commit 024480bf8d

View File

@ -495,7 +495,7 @@ void device_pm_move_to_tail(struct device *dev)
#define to_devlink(dev) container_of((dev), struct device_link, link_dev)
static ssize_t status_show(struct device *dev,
struct device_attribute *attr, char *buf)
const struct device_attribute *attr, char *buf)
{
const char *output;
@ -525,10 +525,10 @@ static ssize_t status_show(struct device *dev,
return sysfs_emit(buf, "%s\n", output);
}
static DEVICE_ATTR_RO(status);
static const DEVICE_ATTR_RO(status);
static ssize_t auto_remove_on_show(struct device *dev,
struct device_attribute *attr, char *buf)
const struct device_attribute *attr, char *buf)
{
struct device_link *link = to_devlink(dev);
const char *output;
@ -542,27 +542,27 @@ static ssize_t auto_remove_on_show(struct device *dev,
return sysfs_emit(buf, "%s\n", output);
}
static DEVICE_ATTR_RO(auto_remove_on);
static const DEVICE_ATTR_RO(auto_remove_on);
static ssize_t runtime_pm_show(struct device *dev,
struct device_attribute *attr, char *buf)
const struct device_attribute *attr, char *buf)
{
struct device_link *link = to_devlink(dev);
return sysfs_emit(buf, "%d\n", device_link_test(link, DL_FLAG_PM_RUNTIME));
}
static DEVICE_ATTR_RO(runtime_pm);
static const DEVICE_ATTR_RO(runtime_pm);
static ssize_t sync_state_only_show(struct device *dev,
struct device_attribute *attr, char *buf)
const struct device_attribute *attr, char *buf)
{
struct device_link *link = to_devlink(dev);
return sysfs_emit(buf, "%d\n", device_link_test(link, DL_FLAG_SYNC_STATE_ONLY));
}
static DEVICE_ATTR_RO(sync_state_only);
static const DEVICE_ATTR_RO(sync_state_only);
static struct attribute *devlink_attrs[] = {
static const struct attribute *const devlink_attrs[] = {
&dev_attr_status.attr,
&dev_attr_auto_remove_on.attr,
&dev_attr_runtime_pm.attr,
@ -1306,7 +1306,7 @@ static void device_link_drop_managed(struct device_link *link)
}
static ssize_t waiting_for_supplier_show(struct device *dev,
struct device_attribute *attr,
const struct device_attribute *attr,
char *buf)
{
bool val;
@ -1317,7 +1317,7 @@ static ssize_t waiting_for_supplier_show(struct device *dev,
device_unlock(dev);
return sysfs_emit(buf, "%u\n", val);
}
static DEVICE_ATTR_RO(waiting_for_supplier);
static const DEVICE_ATTR_RO(waiting_for_supplier);
/**
* device_links_force_bind - Prepares device to be force bound
@ -2792,7 +2792,7 @@ static const struct kset_uevent_ops device_uevent_ops = {
.uevent = dev_uevent,
};
static ssize_t uevent_show(struct device *dev, struct device_attribute *attr,
static ssize_t uevent_show(struct device *dev, const struct device_attribute *attr,
char *buf)
{
struct kobject *top_kobj;
@ -2835,7 +2835,7 @@ static ssize_t uevent_show(struct device *dev, struct device_attribute *attr,
return len;
}
static ssize_t uevent_store(struct device *dev, struct device_attribute *attr,
static ssize_t uevent_store(struct device *dev, const struct device_attribute *attr,
const char *buf, size_t count)
{
int rc;
@ -2849,9 +2849,9 @@ static ssize_t uevent_store(struct device *dev, struct device_attribute *attr,
return count;
}
static DEVICE_ATTR_RW(uevent);
static const DEVICE_ATTR_RW(uevent);
static ssize_t online_show(struct device *dev, struct device_attribute *attr,
static ssize_t online_show(struct device *dev, const struct device_attribute *attr,
char *buf)
{
bool val;
@ -2862,7 +2862,7 @@ static ssize_t online_show(struct device *dev, struct device_attribute *attr,
return sysfs_emit(buf, "%u\n", val);
}
static ssize_t online_store(struct device *dev, struct device_attribute *attr,
static ssize_t online_store(struct device *dev, const struct device_attribute *attr,
const char *buf, size_t count)
{
bool val;
@ -2880,9 +2880,9 @@ static ssize_t online_store(struct device *dev, struct device_attribute *attr,
unlock_device_hotplug();
return ret < 0 ? ret : count;
}
static DEVICE_ATTR_RW(online);
static const DEVICE_ATTR_RW(online);
static ssize_t removable_show(struct device *dev, struct device_attribute *attr,
static ssize_t removable_show(struct device *dev, const struct device_attribute *attr,
char *buf)
{
const char *loc;
@ -2899,7 +2899,7 @@ static ssize_t removable_show(struct device *dev, struct device_attribute *attr,
}
return sysfs_emit(buf, "%s\n", loc);
}
static DEVICE_ATTR_RO(removable);
static const DEVICE_ATTR_RO(removable);
int device_add_groups(struct device *dev,
const struct attribute_group *const *groups)
@ -3050,12 +3050,12 @@ static void device_remove_attrs(struct device *dev)
device_remove_groups(dev, class->dev_groups);
}
static ssize_t dev_show(struct device *dev, struct device_attribute *attr,
static ssize_t dev_show(struct device *dev, const struct device_attribute *attr,
char *buf)
{
return print_dev_t(buf, dev->devt);
}
static DEVICE_ATTR_RO(dev);
static const DEVICE_ATTR_RO(dev);
/* /sys/devices/ */
struct kset *devices_kset;