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

HID: roccat: common, konepure, ryos, savu: 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 d8028671
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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[] = {
+2 −2
Original line number Diff line number Diff line
@@ -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[] = {
+2 −2
Original line number Diff line number Diff line
@@ -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[] = {