[PATCH v3 8/9] platform/wmi: Make sysfs attributes const

Armin Wolf
2026-03-14T17:53:15Z

The sysfs core supports const attributes. Use this to mark all
sysfs attributes as const so that they can be placed into read-only
memory for better security.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
drivers/platform/wmi/core.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/platform/wmi/core.c b/drivers/platform/wmi/core.c
index 082c85625878..1b5bb3410252 100644
--- a/drivers/platform/wmi/core.c
+++ b/drivers/platform/wmi/core.c
@@ -812,7 +812,8 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,

return sysfs_emit(buf, "wmi:%pUL\n", &wblock->gblock.guid);
}
-static DEVICE_ATTR_RO(modalias);
+
+static const DEVICE_ATTR_RO(modalias);

static ssize_t guid_show(struct device *dev, struct device_attribute *attr,
char *buf)
@@ -821,7 +822,8 @@ static ssize_t guid_show(struct device *dev, struct device_attribute *attr,

return sysfs_emit(buf, "%pUL\n", &wblock->gblock.guid);
}
-static DEVICE_ATTR_RO(guid);
+
+static const DEVICE_ATTR_RO(guid);

static ssize_t instance_count_show(struct device *dev,
struct device_attribute *attr, char *buf)
@@ -830,7 +832,8 @@ static ssize_t instance_count_show(struct device *dev,

return sysfs_emit(buf, "%d\n", (int)wblock->gblock.instance_count);
}
-static DEVICE_ATTR_RO(instance_count);
+
+static const DEVICE_ATTR_RO(instance_count);

static ssize_t expensive_show(struct device *dev,
struct device_attribute *attr, char *buf)
@@ -840,7 +843,8 @@ static ssize_t expensive_show(struct device *dev,
return sysfs_emit(buf, "%d\n",
(wblock->gblock.flags & ACPI_WMI_EXPENSIVE) != 0);
}
-static DEVICE_ATTR_RO(expensive);
+
+static const DEVICE_ATTR_RO(expensive);

static ssize_t driver_override_show(struct device *dev, struct device_attribute *attr,
char *buf)
@@ -867,9 +871,10 @@ static ssize_t driver_override_store(struct device *dev, struct device_attribute

return count;
}
-static DEVICE_ATTR_RW(driver_override);

-static struct attribute *wmi_attrs[] = {
+static const DEVICE_ATTR_RW(driver_override);
+
+static const struct attribute * const wmi_attrs[] = {
&dev_attr_modalias.attr,
&dev_attr_guid.attr,
&dev_attr_instance_count.attr,
@@ -886,9 +891,10 @@ static ssize_t notify_id_show(struct device *dev, struct device_attribute *attr,

return sysfs_emit(buf, "%02X\n", (unsigned int)wblock->gblock.notify_id);
}
-static DEVICE_ATTR_RO(notify_id);

-static struct attribute *wmi_event_attrs[] = {
+static const DEVICE_ATTR_RO(notify_id);
+
+static const struct attribute * const wmi_event_attrs[] = {
&dev_attr_notify_id.attr,
NULL
};
@@ -902,7 +908,8 @@ static ssize_t object_id_show(struct device *dev, struct device_attribute *attr,
return sysfs_emit(buf, "%c%c\n", wblock->gblock.object_id[0],
wblock->gblock.object_id[1]);
}
-static DEVICE_ATTR_RO(object_id);
+
+static const DEVICE_ATTR_RO(object_id);

static ssize_t setable_show(struct device *dev, struct device_attribute *attr,
char *buf)
@@ -911,16 +918,17 @@ static ssize_t setable_show(struct device *dev, struct device_attribute *attr,

return sysfs_emit(buf, "%d\n", (int)wdev->setable);
}
-static DEVICE_ATTR_RO(setable);

-static struct attribute *wmi_data_attrs[] = {
+static const DEVICE_ATTR_RO(setable);
+
+static const struct attribute * const wmi_data_attrs[] = {
&dev_attr_object_id.attr,
&dev_attr_setable.attr,
NULL
};
ATTRIBUTE_GROUPS(wmi_data);

-static struct attribute *wmi_method_attrs[] = {
+static const struct attribute * const wmi_method_attrs[] = {
&dev_attr_object_id.attr,
NULL
};
--
2.39.5