Commit cdc6829c authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Jiri Kosina
Browse files

HID: roccat: lua: constify 'struct bin_attribute'



The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.

Signed-off-by: default avatarThomas Weißschuh <linux@weissschuh.net>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.com>
parent 79ef5c35
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ static ssize_t lua_sysfs_write(struct file *fp, struct kobject *kobj,

#define LUA_SYSFS_W(thingy, THINGY) \
static ssize_t lua_sysfs_write_ ## thingy(struct file *fp, \
		struct kobject *kobj, struct bin_attribute *attr, \
		struct kobject *kobj, const struct bin_attribute *attr, \
		char *buf, loff_t off, size_t count) \
{ \
	return lua_sysfs_write(fp, kobj, buf, off, count, \
@@ -75,7 +75,7 @@ static ssize_t lua_sysfs_write_ ## thingy(struct file *fp, \

#define LUA_SYSFS_R(thingy, THINGY) \
static ssize_t lua_sysfs_read_ ## thingy(struct file *fp, \
		struct kobject *kobj, struct bin_attribute *attr, \
		struct kobject *kobj, const struct bin_attribute *attr, \
		char *buf, loff_t off, size_t count) \
{ \
	return lua_sysfs_read(fp, kobj, buf, off, count, \
@@ -85,11 +85,11 @@ static ssize_t lua_sysfs_read_ ## thingy(struct file *fp, \
#define LUA_BIN_ATTRIBUTE_RW(thingy, THINGY) \
LUA_SYSFS_W(thingy, THINGY) \
LUA_SYSFS_R(thingy, THINGY) \
static struct bin_attribute lua_ ## thingy ## _attr = { \
static const struct bin_attribute lua_ ## thingy ## _attr = { \
	.attr = { .name = #thingy, .mode = 0660 }, \
	.size = LUA_SIZE_ ## THINGY, \
	.read = lua_sysfs_read_ ## thingy, \
	.write = lua_sysfs_write_ ## thingy \
	.read_new = lua_sysfs_read_ ## thingy, \
	.write_new = lua_sysfs_write_ ## thingy \
};

LUA_BIN_ATTRIBUTE_RW(control, CONTROL)