[PATCH] Driver Core patches for 2.6.7

From: Greg KH
Date: Tue Jun 22 2004 - 18:19:09 EST


ChangeSet 1.1722.85.1, 2004/06/02 17:10:52-07:00, mochel@xxxxxxxxxxxxxxxxxx

[Driver Model] Consolidate attribute definition macros

- Create __ATTR(), __ATTR_RO(), and __ATTR_NULL macros to help define
attributes in a neat, short-hand form.

- Apply these macros to the attribute definition in include/linux/device.h

- Note: These can be used to more cleanly define attributes in your own
code. e.g:

static struct device_attribute attrs[] = {
__ATTR_RO(foo),
__ATTR_RO(bar),
__ATTR(baz,0666,baz_show,baz_store),
__ATTR_NULL,
};

...etc.

Signed-off-by: Greg Kroah-Hartman <greg@xxxxxxxxx>


include/linux/device.h | 31 ++++++-------------------------
include/linux/sysfs.h | 21 +++++++++++++++++++++
2 files changed, 27 insertions(+), 25 deletions(-)


diff -Nru a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h Tue Jun 22 09:49:19 2004
+++ b/include/linux/device.h Tue Jun 22 09:49:19 2004
@@ -90,11 +90,7 @@
};

#define BUS_ATTR(_name,_mode,_show,_store) \
-struct bus_attribute bus_attr_##_name = { \
- .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
- .show = _show, \
- .store = _store, \
-};
+struct bus_attribute bus_attr_##_name = __ATTR(_name,_mode,_show,_store)

extern int bus_create_file(struct bus_type *, struct bus_attribute *);
extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
@@ -131,11 +127,7 @@
};

#define DRIVER_ATTR(_name,_mode,_show,_store) \
-struct driver_attribute driver_attr_##_name = { \
- .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
- .show = _show, \
- .store = _store, \
-};
+struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store)

extern int driver_create_file(struct device_driver *, struct driver_attribute *);
extern void driver_remove_file(struct device_driver *, struct driver_attribute *);
@@ -172,11 +164,7 @@
};

#define CLASS_ATTR(_name,_mode,_show,_store) \
-struct class_attribute class_attr_##_name = { \
- .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
- .show = _show, \
- .store = _store, \
-};
+struct class_attribute class_attr_##_name = __ATTR(_name,_mode,_show,_store)

extern int class_create_file(struct class *, const struct class_attribute *);
extern void class_remove_file(struct class *, const struct class_attribute *);
@@ -224,11 +212,8 @@
};

#define CLASS_DEVICE_ATTR(_name,_mode,_show,_store) \
-struct class_device_attribute class_device_attr_##_name = { \
- .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
- .show = _show, \
- .store = _store, \
-};
+struct class_device_attribute class_device_attr_##_name = \
+ __ATTR(_name,_mode,_show,_store)

extern int class_device_create_file(struct class_device *,
const struct class_device_attribute *);
@@ -342,11 +327,7 @@
};

#define DEVICE_ATTR(_name,_mode,_show,_store) \
-struct device_attribute dev_attr_##_name = { \
- .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
- .show = _show, \
- .store = _store, \
-};
+struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store)


extern int device_create_file(struct device *device, struct device_attribute * entry);
diff -Nru a/include/linux/sysfs.h b/include/linux/sysfs.h
--- a/include/linux/sysfs.h Tue Jun 22 09:49:19 2004
+++ b/include/linux/sysfs.h Tue Jun 22 09:49:19 2004
@@ -24,6 +24,27 @@
};


+
+/**
+ * Use these macros to make defining attributes easier. See include/linux/device.h
+ * for examples..
+ */
+
+#define __ATTR(_name,_mode,_show,_store) { \
+ .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
+ .show = _show, \
+ .store = _store, \
+}
+
+#define __ATTR_RO(_name) { \
+ .attr = { .name = __stringify(_name), .mode = 0444, .owner = THIS_MODULE }, \
+ .show = _name##_show, \
+}
+
+#define __ATTR_NULL { .attr = { .name = NULL } }
+
+
+
struct bin_attribute {
struct attribute attr;
size_t size;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/