sysfs.h: add BIN_ATTR macro
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 14 Jul 2013 23:05:53 +0000 (16:05 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 16 Jul 2013 17:57:36 +0000 (10:57 -0700)
This makes it easier to create static binary attributes, which is needed
in a number of drivers, instead of "open coding" them.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/sysfs.h

index f62ff01e5f5994ab3cd2cb48b7097253e30e1808..d50a96b9bb6d47a4a1485d1ee2b94fdf64a72f0f 100644 (file)
@@ -132,6 +132,15 @@ struct bin_attribute {
  */
 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
 
+/* macro to create static binary attributes easier */
+#define BIN_ATTR(_name, _mode, _read, _write, _size)           \
+struct bin_attribute bin_attr_##_name = {                      \
+       .attr = {.name = __stringify(_name), .mode = _mode },   \
+       .read   = _read,                                        \
+       .write  = _write,                                       \
+       .size   = _size,                                        \
+}
+
 struct sysfs_ops {
        ssize_t (*show)(struct kobject *, struct attribute *,char *);
        ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);