Skip to content

Instantly share code, notes, and snippets.

@kwilczynski
Created March 3, 2021 22:16
Show Gist options
  • Save kwilczynski/7960bba52f1404e5e0ba353f7ddcca1e to your computer and use it in GitHub Desktop.
Save kwilczynski/7960bba52f1404e5e0ba353f7ddcca1e to your computer and use it in GitHub Desktop.
diff --git i/include/linux/sysfs.h w/include/linux/sysfs.h
index d76a1ddf83a3..9a3dd616881a 100644
--- i/include/linux/sysfs.h
+++ w/include/linux/sysfs.h
@@ -205,6 +205,13 @@ struct bin_attribute {
.size = _size, \
}
+#define __BIN_ATTR_RO_MODE(_name, _mode, _size) { \
+ .attr = { .name = __stringify(_name), \
+ .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
+ .read = _name##_read, \
+ .size = _size, \
+}
+
#define __BIN_ATTR_WO(_name, _size) { \
.attr = { .name = __stringify(_name), .mode = 0200 }, \
.write = _name##_write, \
@@ -214,6 +221,14 @@ struct bin_attribute {
#define __BIN_ATTR_RW(_name, _size) \
__BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
+#define __BIN_ATTR_RW_MODE(_name, _mode, _size) { \
+ .attr = { .name = __stringify(_name), \
+ .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
+ .read = _name##_read, \
+ .write = _name##_write, \
+ .size = _size, \
+}
+
#define __BIN_ATTR_NULL __ATTR_NULL
#define BIN_ATTR(_name, _mode, _read, _write, _size) \
@@ -223,12 +238,19 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read, \
#define BIN_ATTR_RO(_name, _size) \
struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
+#define BIN_ATTR_ADMIN_RO(_name, _size) \
+struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO_MODE(_name, 0400, \
+ _size)
#define BIN_ATTR_WO(_name, _size) \
struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
#define BIN_ATTR_RW(_name, _size) \
struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
+#define BIN_ATTR_ADMIN_RW(_name, _size) \
+struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW_MODE(_name, 0600, \
+ _size)
+
struct sysfs_ops {
ssize_t (*show)(struct kobject *, struct attribute *, char *);
ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment