* [PATCH 1/5] driver core: Delete DEVICE_ATTR_PREALLOC()
2026-04-08 19:30 [PATCH 0/5] driver core: Allow the constification of device attributes Thomas Weißschuh
@ 2026-04-08 19:30 ` Thomas Weißschuh
2026-04-08 19:30 ` [PATCH 2/5] driver core: Add low-level macros for device attributes Thomas Weißschuh
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-08 19:30 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich
Cc: driver-core, linux-kernel, Thomas Weißschuh
This macro is unused and would create extra work during the upcoming
constification of device attributes. Remove it.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
include/linux/device.h | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/include/linux/device.h b/include/linux/device.h
index f0d52e1a6e07..8ba3168180e5 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -157,19 +157,6 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
#define DEVICE_ATTR(_name, _mode, _show, _store) \
struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
-/**
- * DEVICE_ATTR_PREALLOC - Define a preallocated device attribute.
- * @_name: Attribute name.
- * @_mode: File mode.
- * @_show: Show handler. Optional, but mandatory if attribute is readable.
- * @_store: Store handler. Optional, but mandatory if attribute is writable.
- *
- * Like DEVICE_ATTR(), but ``SYSFS_PREALLOC`` is set on @_mode.
- */
-#define DEVICE_ATTR_PREALLOC(_name, _mode, _show, _store) \
- struct device_attribute dev_attr_##_name = \
- __ATTR_PREALLOC(_name, _mode, _show, _store)
-
/**
* DEVICE_ATTR_RW - Define a read-write device attribute.
* @_name: Attribute name.
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/5] driver core: Add low-level macros for device attributes
2026-04-08 19:30 [PATCH 0/5] driver core: Allow the constification of device attributes Thomas Weißschuh
2026-04-08 19:30 ` [PATCH 1/5] driver core: Delete DEVICE_ATTR_PREALLOC() Thomas Weißschuh
@ 2026-04-08 19:30 ` Thomas Weißschuh
2026-04-08 19:30 ` [PATCH 3/5] driver core: stop using generic sysfs " Thomas Weißschuh
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-08 19:30 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich
Cc: driver-core, linux-kernel, Thomas Weißschuh
For the upcoming constification of device attributes the generic
__ATTR() macros are insufficient.
Prepare for a split by introducing new low-level macros specific to
device attributes.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
include/linux/device.h | 43 ++++++++++++++++++++++++++++++++-----------
1 file changed, 32 insertions(+), 11 deletions(-)
diff --git a/include/linux/device.h b/include/linux/device.h
index 8ba3168180e5..a0384dac06ee 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -135,6 +135,27 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
char *buf);
+#define __DEVICE_ATTR(_name, _mode, _show, _store) \
+ __ATTR(_name, _mode, _show, _store)
+
+#define __DEVICE_ATTR_RO_MODE(_name, _mode) \
+ __ATTR_RO_MODE(_name, _mode)
+
+#define __DEVICE_ATTR_RO(_name) \
+ __ATTR_RO(_name)
+
+#define __DEVICE_ATTR_WO(_name) \
+ __ATTR_WO(_name)
+
+#define __DEVICE_ATTR_RW_MODE(_name, _mode) \
+ __ATTR_RW_MODE(_name, _mode)
+
+#define __DEVICE_ATTR_RW(_name) \
+ __ATTR_RW(_name)
+
+#define __DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
+ __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
+
/**
* DEVICE_ATTR - Define a device attribute.
* @_name: Attribute name.
@@ -155,7 +176,7 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
* };
*/
#define DEVICE_ATTR(_name, _mode, _show, _store) \
- struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
+ struct device_attribute dev_attr_##_name = __DEVICE_ATTR(_name, _mode, _show, _store)
/**
* DEVICE_ATTR_RW - Define a read-write device attribute.
@@ -165,7 +186,7 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
* and @_store is <_name>_store.
*/
#define DEVICE_ATTR_RW(_name) \
- struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
+ struct device_attribute dev_attr_##_name = __DEVICE_ATTR_RW(_name)
/**
* DEVICE_ATTR_ADMIN_RW - Define an admin-only read-write device attribute.
@@ -174,7 +195,7 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
* Like DEVICE_ATTR_RW(), but @_mode is 0600.
*/
#define DEVICE_ATTR_ADMIN_RW(_name) \
- struct device_attribute dev_attr_##_name = __ATTR_RW_MODE(_name, 0600)
+ struct device_attribute dev_attr_##_name = __DEVICE_ATTR_RW_MODE(_name, 0600)
/**
* DEVICE_ATTR_RO - Define a readable device attribute.
@@ -183,7 +204,7 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
* Like DEVICE_ATTR(), but @_mode is 0444 and @_show is <_name>_show.
*/
#define DEVICE_ATTR_RO(_name) \
- struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
+ struct device_attribute dev_attr_##_name = __DEVICE_ATTR_RO(_name)
/**
* DEVICE_ATTR_ADMIN_RO - Define an admin-only readable device attribute.
@@ -192,7 +213,7 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
* Like DEVICE_ATTR_RO(), but @_mode is 0400.
*/
#define DEVICE_ATTR_ADMIN_RO(_name) \
- struct device_attribute dev_attr_##_name = __ATTR_RO_MODE(_name, 0400)
+ struct device_attribute dev_attr_##_name = __DEVICE_ATTR_RO_MODE(_name, 0400)
/**
* DEVICE_ATTR_WO - Define an admin-only writable device attribute.
@@ -201,7 +222,7 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
* Like DEVICE_ATTR(), but @_mode is 0200 and @_store is <_name>_store.
*/
#define DEVICE_ATTR_WO(_name) \
- struct device_attribute dev_attr_##_name = __ATTR_WO(_name)
+ struct device_attribute dev_attr_##_name = __DEVICE_ATTR_WO(_name)
/**
* DEVICE_ULONG_ATTR - Define a device attribute backed by an unsigned long.
@@ -214,7 +235,7 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
*/
#define DEVICE_ULONG_ATTR(_name, _mode, _var) \
struct dev_ext_attribute dev_attr_##_name = \
- { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) }
+ { __DEVICE_ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) }
/**
* DEVICE_INT_ATTR - Define a device attribute backed by an int.
@@ -226,7 +247,7 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
*/
#define DEVICE_INT_ATTR(_name, _mode, _var) \
struct dev_ext_attribute dev_attr_##_name = \
- { __ATTR(_name, _mode, device_show_int, device_store_int), &(_var) }
+ { __DEVICE_ATTR(_name, _mode, device_show_int, device_store_int), &(_var) }
/**
* DEVICE_BOOL_ATTR - Define a device attribute backed by a bool.
@@ -238,7 +259,7 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
*/
#define DEVICE_BOOL_ATTR(_name, _mode, _var) \
struct dev_ext_attribute dev_attr_##_name = \
- { __ATTR(_name, _mode, device_show_bool, device_store_bool), &(_var) }
+ { __DEVICE_ATTR(_name, _mode, device_show_bool, device_store_bool), &(_var) }
/**
* DEVICE_STRING_ATTR_RO - Define a device attribute backed by a r/o string.
@@ -251,11 +272,11 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
*/
#define DEVICE_STRING_ATTR_RO(_name, _mode, _var) \
struct dev_ext_attribute dev_attr_##_name = \
- { __ATTR(_name, (_mode) & ~0222, device_show_string, NULL), (_var) }
+ { __DEVICE_ATTR(_name, (_mode) & ~0222, device_show_string, NULL), (_var) }
#define DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
struct device_attribute dev_attr_##_name = \
- __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
+ __DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
int device_create_file(struct device *device,
const struct device_attribute *entry);
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/5] driver core: stop using generic sysfs macros for device attributes
2026-04-08 19:30 [PATCH 0/5] driver core: Allow the constification of device attributes Thomas Weißschuh
2026-04-08 19:30 ` [PATCH 1/5] driver core: Delete DEVICE_ATTR_PREALLOC() Thomas Weißschuh
2026-04-08 19:30 ` [PATCH 2/5] driver core: Add low-level macros for device attributes Thomas Weißschuh
@ 2026-04-08 19:30 ` Thomas Weißschuh
2026-04-08 19:30 ` [PATCH 4/5] driver core: Allow the constification of " Thomas Weißschuh
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-08 19:30 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich
Cc: driver-core, linux-kernel, Thomas Weißschuh
The constification of device attributes will require a transition phase,
where 'struct device_attribute' contains a classic non-const and a new
const variant of the 'show' and 'store' callbacks.
As __ATTR() and friends can not handle this duplication stop using them.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
include/linux/device.h | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/include/linux/device.h b/include/linux/device.h
index a0384dac06ee..714e36d610e3 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -135,26 +135,38 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
char *buf);
-#define __DEVICE_ATTR(_name, _mode, _show, _store) \
- __ATTR(_name, _mode, _show, _store)
+#define __DEVICE_ATTR(_name, _mode, _show, _store) { \
+ .attr = {.name = __stringify(_name), \
+ .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
+ .show = _show, \
+ .store = _store, \
+}
#define __DEVICE_ATTR_RO_MODE(_name, _mode) \
- __ATTR_RO_MODE(_name, _mode)
+ __DEVICE_ATTR(_name, _mode, _name##_show, NULL)
#define __DEVICE_ATTR_RO(_name) \
- __ATTR_RO(_name)
+ __DEVICE_ATTR_RO_MODE(_name, 0444)
#define __DEVICE_ATTR_WO(_name) \
- __ATTR_WO(_name)
+ __DEVICE_ATTR(_name, 0200, NULL, _name##_store)
#define __DEVICE_ATTR_RW_MODE(_name, _mode) \
- __ATTR_RW_MODE(_name, _mode)
+ __DEVICE_ATTR(_name, _mode, _name##_show, _name##_store)
#define __DEVICE_ATTR_RW(_name) \
- __ATTR_RW(_name)
-
-#define __DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) \
- __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
+ __DEVICE_ATTR_RW_MODE(_name, 0644)
+
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+#define __DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) { \
+ .attr = {.name = __stringify(_name), .mode = _mode, \
+ .ignore_lockdep = true }, \
+ .show = _show, \
+ .store = _store, \
+}
+#else
+#define __DEVICE_ATTR_IGNORE_LOCKDEP __DEVICE_ATTR
+#endif
/**
* DEVICE_ATTR - Define a device attribute.
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 4/5] driver core: Allow the constification of device attributes
2026-04-08 19:30 [PATCH 0/5] driver core: Allow the constification of device attributes Thomas Weißschuh
` (2 preceding siblings ...)
2026-04-08 19:30 ` [PATCH 3/5] driver core: stop using generic sysfs " Thomas Weißschuh
@ 2026-04-08 19:30 ` Thomas Weißschuh
2026-04-08 19:30 ` [PATCH 5/5] driver core: Constify core " Thomas Weißschuh
2026-04-09 5:36 ` [PATCH 0/5] driver core: Allow the constification of " Greg Kroah-Hartman
5 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-08 19:30 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich
Cc: driver-core, linux-kernel, Thomas Weißschuh
Allow device attribute to reside in read-only memory.
Both const and non-const attributes are handled by the utility macros
and attributes can be migrated one-by-one.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
drivers/base/core.c | 12 ++++++----
include/linux/device.h | 62 +++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 62 insertions(+), 12 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 763e17e9f148..8a48cb2137ae 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2419,9 +2419,11 @@ static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
if (dev_attr->show)
ret = dev_attr->show(dev, dev_attr, buf);
+ else if (dev_attr->show_const)
+ ret = dev_attr->show_const(dev, dev_attr, buf);
if (ret >= (ssize_t)PAGE_SIZE) {
- printk("dev_attr_show: %pS returned bad count\n",
- dev_attr->show);
+ printk("dev_attr_show: %pS/%pS returned bad count\n",
+ dev_attr->show, dev_attr->show_const);
}
return ret;
}
@@ -2435,6 +2437,8 @@ static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
if (dev_attr->store)
ret = dev_attr->store(dev, dev_attr, buf, count);
+ else if (dev_attr->store_const)
+ ret = dev_attr->store_const(dev, dev_attr, buf, count);
return ret;
}
@@ -3048,10 +3052,10 @@ int device_create_file(struct device *dev,
int error = 0;
if (dev) {
- WARN(((attr->attr.mode & S_IWUGO) && !attr->store),
+ WARN(((attr->attr.mode & S_IWUGO) && !(attr->store || attr->store_const)),
"Attribute %s: write permission without 'store'\n",
attr->attr.name);
- WARN(((attr->attr.mode & S_IRUGO) && !attr->show),
+ WARN(((attr->attr.mode & S_IRUGO) && !(attr->show || attr->show_const)),
"Attribute %s: read permission without 'show'\n",
attr->attr.name);
error = sysfs_create_file(&dev->kobj, &attr->attr);
diff --git a/include/linux/device.h b/include/linux/device.h
index 714e36d610e3..a529a8eaaa9a 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -104,10 +104,18 @@ struct device_type {
*/
struct device_attribute {
struct attribute attr;
- ssize_t (*show)(struct device *dev, struct device_attribute *attr,
- char *buf);
- ssize_t (*store)(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count);
+ __SYSFS_FUNCTION_ALTERNATIVE(
+ ssize_t (*show)(struct device *dev, struct device_attribute *attr,
+ char *buf);
+ ssize_t (*show_const)(struct device *dev, const struct device_attribute *attr,
+ char *buf);
+ );
+ __SYSFS_FUNCTION_ALTERNATIVE(
+ ssize_t (*store)(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count);
+ ssize_t (*store_const)(struct device *dev, const struct device_attribute *attr,
+ const char *buf, size_t count);
+ );
};
/**
@@ -135,11 +143,50 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
char *buf);
+typedef ssize_t __device_show_handler_const(struct device *dev, const struct device_attribute *attr,
+ char *buf);
+typedef ssize_t __device_store_handler_const(struct device *dev, const struct device_attribute *attr,
+ const char *buf, size_t count);
+
+#ifdef CONFIG_CFI
+
+#define __DEVICE_ATTR_SHOW_STORE(_show, _store) \
+ .show = _Generic(_show, \
+ __device_show_handler_const * : NULL, \
+ default : _show \
+ ), \
+ .show_const = _Generic(_show, \
+ __device_show_handler_const * : _show, \
+ default : NULL \
+ ), \
+ .store = _Generic(_store, \
+ __device_store_handler_const * : NULL, \
+ default : _store \
+ ), \
+ .store_const = _Generic(_store, \
+ __device_store_handler_const * : _store, \
+ default : NULL \
+ ),
+
+#else
+
+#define __DEVICE_ATTR_SHOW_STORE(_show, _store) \
+ .show = _Generic(_show, \
+ __device_show_handler_const * : (void *)_show, \
+ default : _show \
+ ), \
+ .store = _Generic(_store, \
+ __device_store_handler_const * : (void *)_store, \
+ default : _store \
+ ), \
+
+#endif
+
+
#define __DEVICE_ATTR(_name, _mode, _show, _store) { \
.attr = {.name = __stringify(_name), \
.mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
- .show = _show, \
- .store = _store, \
+ __DEVICE_ATTR_SHOW_STORE(_show, _store) \
}
#define __DEVICE_ATTR_RO_MODE(_name, _mode) \
@@ -161,8 +208,7 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,
#define __DEVICE_ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) { \
.attr = {.name = __stringify(_name), .mode = _mode, \
.ignore_lockdep = true }, \
- .show = _show, \
- .store = _store, \
+ __DEVICE_ATTR_SHOW_STORE(_show, _store) \
}
#else
#define __DEVICE_ATTR_IGNORE_LOCKDEP __DEVICE_ATTR
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 5/5] driver core: Constify core device attributes
2026-04-08 19:30 [PATCH 0/5] driver core: Allow the constification of device attributes Thomas Weißschuh
` (3 preceding siblings ...)
2026-04-08 19:30 ` [PATCH 4/5] driver core: Allow the constification of " Thomas Weißschuh
@ 2026-04-08 19:30 ` Thomas Weißschuh
2026-04-09 5:36 ` [PATCH 0/5] driver core: Allow the constification of " Greg Kroah-Hartman
5 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-08 19:30 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich
Cc: driver-core, linux-kernel, Thomas Weißschuh
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>
---
drivers/base/core.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 8a48cb2137ae..0f314c83eb9d 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -422,7 +422,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;
@@ -452,10 +452,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;
@@ -469,27 +469,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,
@@ -1233,7 +1233,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;
@@ -1244,7 +1244,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
@@ -2727,7 +2727,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;
@@ -2770,7 +2770,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;
@@ -2784,9 +2784,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;
@@ -2797,7 +2797,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;
@@ -2815,9 +2815,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;
@@ -2834,7 +2834,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)
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 0/5] driver core: Allow the constification of device attributes
2026-04-08 19:30 [PATCH 0/5] driver core: Allow the constification of device attributes Thomas Weißschuh
` (4 preceding siblings ...)
2026-04-08 19:30 ` [PATCH 5/5] driver core: Constify core " Thomas Weißschuh
@ 2026-04-09 5:36 ` Greg Kroah-Hartman
2026-04-09 8:47 ` Thomas Weißschuh
5 siblings, 1 reply; 8+ messages in thread
From: Greg Kroah-Hartman @ 2026-04-09 5:36 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Rafael J. Wysocki, Danilo Krummrich, driver-core, linux-kernel
On Wed, Apr 08, 2026 at 09:30:46PM +0200, Thomas Weißschuh wrote:
> Allow device attribute to reside in read-only memory.
> Both const and non-const attributes are handled by the utility macros
> and attributes can be migrated one-by-one.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> Thomas Weißschuh (5):
> driver core: Delete DEVICE_ATTR_PREALLOC()
> driver core: Add low-level macros for device attributes
> driver core: stop using generic sysfs macros for device attributes
> driver core: Allow the constification of device attributes
> driver core: Constify core device attributes
>
> drivers/base/core.c | 50 ++++++++++----------
> include/linux/device.h | 122 +++++++++++++++++++++++++++++++++++++------------
> 2 files changed, 121 insertions(+), 51 deletions(-)
> ---
> base-commit: 6c8dfb0362732bf1e4829867a2a5239fedc592d0
> change-id: 20260408-sysfs-const-attr-device_attr-prep-9971fb4439da
>
> Best regards,
> --
> Thomas Weißschuh <linux@weissschuh.net>
>
>
We still have the is_visible_const() stuff not finished yet, why not fix
that up first?
And this makes me worry, how many changes are going to be needed to move
everything over? thousands?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 0/5] driver core: Allow the constification of device attributes
2026-04-09 5:36 ` [PATCH 0/5] driver core: Allow the constification of " Greg Kroah-Hartman
@ 2026-04-09 8:47 ` Thomas Weißschuh
0 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-04-09 8:47 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Rafael J. Wysocki, Danilo Krummrich, driver-core, linux-kernel
On 2026-04-09 07:36:09+0200, Greg Kroah-Hartman wrote:
> On Wed, Apr 08, 2026 at 09:30:46PM +0200, Thomas Weißschuh wrote:
> > Allow device attribute to reside in read-only memory.
> > Both const and non-const attributes are handled by the utility macros
> > and attributes can be migrated one-by-one.
> >
> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > ---
> > Thomas Weißschuh (5):
> > driver core: Delete DEVICE_ATTR_PREALLOC()
> > driver core: Add low-level macros for device attributes
> > driver core: stop using generic sysfs macros for device attributes
> > driver core: Allow the constification of device attributes
> > driver core: Constify core device attributes
> >
> > drivers/base/core.c | 50 ++++++++++----------
> > include/linux/device.h | 122 +++++++++++++++++++++++++++++++++++++------------
> > 2 files changed, 121 insertions(+), 51 deletions(-)
> > ---
> > base-commit: 6c8dfb0362732bf1e4829867a2a5239fedc592d0
> > change-id: 20260408-sysfs-const-attr-device_attr-prep-9971fb4439da
> >
> > Best regards,
> > --
> > Thomas Weißschuh <linux@weissschuh.net>
> >
> >
>
> We still have the is_visible_const() stuff not finished yet, why not fix
> that up first?
Because I want to touch each file or subsystem as few times as
possible. So before a subsystem is migrated, the prerequisites for
all of their used features need to be there.
Currently only the prerequisites for 'struct device_attribute' and
'struct kobj_attribute' are missing. So with this series in we can start
migrating everything that is *not* using 'struct kobj_attribute'.
> And this makes me worry, how many changes are going to be needed to move
> everything over? thousands?
Depends on the granularity of the patches. I want to do as few as
possible, but still expect a few hundred patches.
Thomas
^ permalink raw reply [flat|nested] 8+ messages in thread