From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Make to_ext_attr() available to code that wants to reuse struct
dev_ext_attribute. While at it: make it into a static inline function.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/base/core.c | 2 --
include/linux/device.h | 6 ++++++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 131d96c6090b..d51e7f05d15a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2459,8 +2459,6 @@ static const struct sysfs_ops dev_sysfs_ops = {
.store = dev_attr_store,
};
-#define to_ext_attr(x) container_of(x, struct dev_ext_attribute, attr)
-
ssize_t device_store_ulong(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
diff --git a/include/linux/device.h b/include/linux/device.h
index fc3bd7116ab9..f7957ec918a3 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -120,6 +120,12 @@ struct dev_ext_attribute {
void *var;
};
+static inline struct dev_ext_attribute *
+to_ext_attr(struct device_attribute *attr)
+{
+ return container_of(attr, struct dev_ext_attribute, attr);
+}
+
ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
char *buf);
ssize_t device_store_ulong(struct device *dev, struct device_attribute *attr,
--
2.43.0
On Thu, Jun 13, 2024 at 11:28:29AM +0200, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > Make to_ext_attr() available to code that wants to reuse struct > dev_ext_attribute. While at it: make it into a static inline function. Please don't use this, why is it needed? thanks, greg k-h
On Thu, Jun 13, 2024 at 12:02 PM Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote: > > On Thu, Jun 13, 2024 at 11:28:29AM +0200, Bartosz Golaszewski wrote: > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > Make to_ext_attr() available to code that wants to reuse struct > > dev_ext_attribute. While at it: make it into a static inline function. > > Please don't use this, why is it needed? > > thanks, > > greg k-h I had a struct in the gpio-virtuser module that consisted of a device_attribute and a void pointer. Andy suggested reusing struct dev_ext_attribute for that but I need this macro to access it when only having the embedded struct device_attribute address. Bart
© 2016 - 2026 Red Hat, Inc.