From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>
Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
"Thomas Weißschuh" <linux@weissschuh.net>
Subject: [PATCH v3 2/5] driver core: Add low-level macros for device attributes
Date: Tue, 12 May 2026 18:39:12 +0200 [thread overview]
Message-ID: <20260512-sysfs-const-attr-device_attr-prep-v3-2-cb7c17b34d52@weissschuh.net> (raw)
In-Reply-To: <20260512-sysfs-const-attr-device_attr-prep-v3-0-cb7c17b34d52@weissschuh.net>
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 06ec4e27a1e1..24ed3a6caad2 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_RW_NAMED - Define a read-write device attribute with a sysfs name
@@ -199,7 +220,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.
@@ -208,7 +229,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_RO_NAMED - Define a read-only device attribute with a sysfs name
@@ -232,7 +253,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_ATTR_WO_NAMED - Define a read-only device attribute with a sysfs name
@@ -260,7 +281,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.
@@ -272,7 +293,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.
@@ -284,7 +305,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.
@@ -297,11 +318,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.54.0
next prev parent reply other threads:[~2026-05-12 16:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 16:39 [PATCH v3 0/5] driver core: Allow the constification of " Thomas Weißschuh
2026-05-12 16:39 ` [PATCH v3 1/5] driver core: Delete DEVICE_ATTR_PREALLOC() Thomas Weißschuh
2026-05-12 16:39 ` Thomas Weißschuh [this message]
2026-05-12 16:39 ` [PATCH v3 3/5] driver core: Stop using generic sysfs macros for device attributes Thomas Weißschuh
2026-05-12 16:39 ` [PATCH v3 4/5] driver core: Allow the constification of " Thomas Weißschuh
2026-05-26 14:52 ` Mark Brown
2026-05-26 15:25 ` Mark Brown
2026-05-26 15:32 ` Danilo Krummrich
2026-05-26 15:38 ` Mark Brown
2026-05-12 16:39 ` [PATCH v3 5/5] driver core: Constify core " Thomas Weißschuh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260512-sysfs-const-attr-device_attr-prep-v3-2-cb7c17b34d52@weissschuh.net \
--to=linux@weissschuh.net \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®