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: Thomas Weißschuh <linux@xxxxxxxxxxxxxx> --- drivers/hid/hid-roccat-common.h | 22 +++++++++++----------- drivers/hid/hid-roccat-konepure.c | 4 ++-- drivers/hid/hid-roccat-ryos.c | 4 ++-- drivers/hid/hid-roccat-savu.c | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/hid/hid-roccat-common.h b/drivers/hid/hid-roccat-common.h index 839ddfd931f076a2c3c2ab3a6d8186004273f2e1..0f9a2db04df96aaa2fe87adc00ec14f8fa30ed82 100644 --- a/drivers/hid/hid-roccat-common.h +++ b/drivers/hid/hid-roccat-common.h @@ -46,8 +46,8 @@ ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj, #define ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \ static ssize_t roccat_common2_sysfs_write_ ## thingy(struct file *fp, \ - struct kobject *kobj, struct bin_attribute *attr, char *buf, \ - loff_t off, size_t count) \ + struct kobject *kobj, const struct bin_attribute *attr, \ + char *buf, loff_t off, size_t count) \ { \ return roccat_common2_sysfs_write(fp, kobj, buf, off, count, \ SIZE, COMMAND); \ @@ -55,8 +55,8 @@ static ssize_t roccat_common2_sysfs_write_ ## thingy(struct file *fp, \ #define ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) \ static ssize_t roccat_common2_sysfs_read_ ## thingy(struct file *fp, \ - struct kobject *kobj, struct bin_attribute *attr, char *buf, \ - loff_t off, size_t count) \ + struct kobject *kobj, const struct bin_attribute *attr, \ + char *buf, loff_t off, size_t count) \ { \ return roccat_common2_sysfs_read(fp, kobj, buf, off, count, \ SIZE, COMMAND); \ @@ -68,27 +68,27 @@ ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) #define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \ ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \ -static struct bin_attribute bin_attr_ ## thingy = { \ +static const struct bin_attribute bin_attr_ ## thingy = { \ .attr = { .name = #thingy, .mode = 0660 }, \ .size = SIZE, \ - .read = roccat_common2_sysfs_read_ ## thingy, \ - .write = roccat_common2_sysfs_write_ ## thingy \ + .read_new = roccat_common2_sysfs_read_ ## thingy, \ + .write_new = roccat_common2_sysfs_write_ ## thingy \ } #define ROCCAT_COMMON2_BIN_ATTRIBUTE_R(thingy, COMMAND, SIZE) \ ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \ -static struct bin_attribute bin_attr_ ## thingy = { \ +static const struct bin_attribute bin_attr_ ## thingy = { \ .attr = { .name = #thingy, .mode = 0440 }, \ .size = SIZE, \ - .read = roccat_common2_sysfs_read_ ## thingy, \ + .read_new = roccat_common2_sysfs_read_ ## thingy, \ } #define ROCCAT_COMMON2_BIN_ATTRIBUTE_W(thingy, COMMAND, SIZE) \ ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \ -static struct bin_attribute bin_attr_ ## thingy = { \ +static const struct bin_attribute bin_attr_ ## thingy = { \ .attr = { .name = #thingy, .mode = 0220 }, \ .size = SIZE, \ - .write = roccat_common2_sysfs_write_ ## thingy \ + .write_new = roccat_common2_sysfs_write_ ## thingy \ } #endif diff --git a/drivers/hid/hid-roccat-konepure.c b/drivers/hid/hid-roccat-konepure.c index beca8aef8bbb2987baabdb588fb0edcad5325473..7fb705789d4eca6c9eeab9b2fc2a1f615bad747e 100644 --- a/drivers/hid/hid-roccat-konepure.c +++ b/drivers/hid/hid-roccat-konepure.c @@ -47,7 +47,7 @@ ROCCAT_COMMON2_BIN_ATTRIBUTE_R(tcu_image, 0x0c, 0x0404); ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0x0f, 0x06); ROCCAT_COMMON2_BIN_ATTRIBUTE_W(talk, 0x10, 0x10); -static struct bin_attribute *konepure_bin_attrs[] = { +static const struct bin_attribute *const konepure_bin_attrs[] = { &bin_attr_actual_profile, &bin_attr_control, &bin_attr_info, @@ -62,7 +62,7 @@ static struct bin_attribute *konepure_bin_attrs[] = { }; static const struct attribute_group konepure_group = { - .bin_attrs = konepure_bin_attrs, + .bin_attrs_new = konepure_bin_attrs, }; static const struct attribute_group *konepure_groups[] = { diff --git a/drivers/hid/hid-roccat-ryos.c b/drivers/hid/hid-roccat-ryos.c index 57714a4525e2ad01b8599db8325b22b57c297158..902dac1e714e16936d8ab7881b183b732cb1c110 100644 --- a/drivers/hid/hid-roccat-ryos.c +++ b/drivers/hid/hid-roccat-ryos.c @@ -47,7 +47,7 @@ ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(stored_lights, 0x17, 0x0566); ROCCAT_COMMON2_BIN_ATTRIBUTE_W(custom_lights, 0x18, 0x14); ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(light_macro, 0x19, 0x07d2); -static struct bin_attribute *ryos_bin_attrs[] = { +static const struct bin_attribute *const ryos_bin_attrs[] = { &bin_attr_control, &bin_attr_profile, &bin_attr_keys_primary, @@ -70,7 +70,7 @@ static struct bin_attribute *ryos_bin_attrs[] = { }; static const struct attribute_group ryos_group = { - .bin_attrs = ryos_bin_attrs, + .bin_attrs_new = ryos_bin_attrs, }; static const struct attribute_group *ryos_groups[] = { diff --git a/drivers/hid/hid-roccat-savu.c b/drivers/hid/hid-roccat-savu.c index 2baa47a0efc527086128b39130dde9535eb541c0..7399b8ffb5c7cae8110c8fb1a93f8b645f54f2eb 100644 --- a/drivers/hid/hid-roccat-savu.c +++ b/drivers/hid/hid-roccat-savu.c @@ -30,7 +30,7 @@ ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(macro, 0x8, 0x0823); ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info, 0x9, 0x08); ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0xc, 0x04); -static struct bin_attribute *savu_bin_attrs[] = { +static const struct bin_attribute *const savu_bin_attrs[] = { &bin_attr_control, &bin_attr_profile, &bin_attr_general, @@ -42,7 +42,7 @@ static struct bin_attribute *savu_bin_attrs[] = { }; static const struct attribute_group savu_group = { - .bin_attrs = savu_bin_attrs, + .bin_attrs_new = savu_bin_attrs, }; static const struct attribute_group *savu_groups[] = { -- 2.47.1