[PATCH 3/5] driver core: stop using generic sysfs macros for device attributes

Thomas Weißschuh
2026-04-08T19:30:51Z

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