sysfs: add more helper macro's for (bin_)attribute(_groups)
authorOliver Schinagl <oliver@schinagl.nl>
Sun, 14 Jul 2013 23:05:59 +0000 (16:05 -0700)
committerMathieu Poirier <mathieu.poirier@linaro.org>
Mon, 22 Dec 2014 17:50:23 +0000 (10:50 -0700)
With the recent changes to sysfs there's various helper macro's.
However there's no RW, RO BIN_ helper macro's. This patch adds them.

Signed-off-by: Oliver Schinagl <oliver@schinagl.nl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 3493f69f4c4e8703961919a9a56c2d2e6a25b46f)
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Conflicts:
include/linux/sysfs.h

include/linux/sysfs.h

index 83678c0887bac52ab8a40996a7d1176945aa8063..b1dc7aa872fd6e22454b20809a8cd95b041c0808 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/list.h>
 #include <linux/lockdep.h>
 #include <linux/kobject_ns.h>
+#include <linux/stat.h>
 #include <linux/atomic.h>
 
 struct kobject;
@@ -95,6 +96,18 @@ struct attribute_group {
 #define __ATTR_IGNORE_LOCKDEP  __ATTR
 #endif
 
+#define __ATTRIBUTE_GROUPS(_name)                              \
+static const struct attribute_group *_name##_groups[] = {      \
+       &_name##_group,                                         \
+       NULL,                                                   \
+}
+
+#define ATTRIBUTE_GROUPS(_name)                                        \
+static const struct attribute_group _name##_group = {          \
+       .attrs = _name##_attrs,                                 \
+};                                                             \
+__ATTRIBUTE_GROUPS(_name)
+
 #define attr_name(_attr) (_attr).attr.name
 
 struct file;
@@ -124,6 +137,36 @@ struct bin_attribute {
  */
 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
 
+/* macros to create static binary attributes easier */
+#define __BIN_ATTR(_name, _mode, _read, _write, _size) {               \
+       .attr = { .name = __stringify(_name), .mode = _mode },          \
+       .read   = _read,                                                \
+       .write  = _write,                                               \
+       .size   = _size,                                                \
+}
+
+#define __BIN_ATTR_RO(_name, _size) {                                  \
+       .attr   = { .name = __stringify(_name), .mode = S_IRUGO },      \
+       .read   = _name##_read,                                         \
+       .size   = _size,                                                \
+}
+
+#define __BIN_ATTR_RW(_name, _size) __BIN_ATTR(_name,                  \
+                                  (S_IWUSR | S_IRUGO), _name##_read,   \
+                                  _name##_write)
+
+#define __BIN_ATTR_NULL __ATTR_NULL
+
+#define BIN_ATTR(_name, _mode, _read, _write, _size)                   \
+struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read,        \
+                                       _write, _size)
+
+#define BIN_ATTR_RO(_name, _size)                                      \
+struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
+
+#define BIN_ATTR_RW(_name, _size)                                      \
+struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
+
 struct sysfs_ops {
        ssize_t (*show)(struct kobject *, struct attribute *,char *);
        ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);