Skip to content

Commit 66f58ab

Browse files
t-8chJiri Kosina
authored andcommitted
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: Thomas Weißschuh <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent d802867 commit 66f58ab

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

drivers/hid/hid-roccat-common.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj,
4646

4747
#define ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
4848
static ssize_t roccat_common2_sysfs_write_ ## thingy(struct file *fp, \
49-
struct kobject *kobj, struct bin_attribute *attr, char *buf, \
50-
loff_t off, size_t count) \
49+
struct kobject *kobj, const struct bin_attribute *attr, \
50+
char *buf, loff_t off, size_t count) \
5151
{ \
5252
return roccat_common2_sysfs_write(fp, kobj, buf, off, count, \
5353
SIZE, COMMAND); \
5454
}
5555

5656
#define ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) \
5757
static ssize_t roccat_common2_sysfs_read_ ## thingy(struct file *fp, \
58-
struct kobject *kobj, struct bin_attribute *attr, char *buf, \
59-
loff_t off, size_t count) \
58+
struct kobject *kobj, const struct bin_attribute *attr, \
59+
char *buf, loff_t off, size_t count) \
6060
{ \
6161
return roccat_common2_sysfs_read(fp, kobj, buf, off, count, \
6262
SIZE, COMMAND); \
@@ -68,27 +68,27 @@ ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE)
6868

6969
#define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \
7070
ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \
71-
static struct bin_attribute bin_attr_ ## thingy = { \
71+
static const struct bin_attribute bin_attr_ ## thingy = { \
7272
.attr = { .name = #thingy, .mode = 0660 }, \
7373
.size = SIZE, \
74-
.read = roccat_common2_sysfs_read_ ## thingy, \
75-
.write = roccat_common2_sysfs_write_ ## thingy \
74+
.read_new = roccat_common2_sysfs_read_ ## thingy, \
75+
.write_new = roccat_common2_sysfs_write_ ## thingy \
7676
}
7777

7878
#define ROCCAT_COMMON2_BIN_ATTRIBUTE_R(thingy, COMMAND, SIZE) \
7979
ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \
80-
static struct bin_attribute bin_attr_ ## thingy = { \
80+
static const struct bin_attribute bin_attr_ ## thingy = { \
8181
.attr = { .name = #thingy, .mode = 0440 }, \
8282
.size = SIZE, \
83-
.read = roccat_common2_sysfs_read_ ## thingy, \
83+
.read_new = roccat_common2_sysfs_read_ ## thingy, \
8484
}
8585

8686
#define ROCCAT_COMMON2_BIN_ATTRIBUTE_W(thingy, COMMAND, SIZE) \
8787
ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \
88-
static struct bin_attribute bin_attr_ ## thingy = { \
88+
static const struct bin_attribute bin_attr_ ## thingy = { \
8989
.attr = { .name = #thingy, .mode = 0220 }, \
9090
.size = SIZE, \
91-
.write = roccat_common2_sysfs_write_ ## thingy \
91+
.write_new = roccat_common2_sysfs_write_ ## thingy \
9292
}
9393

9494
#endif

drivers/hid/hid-roccat-konepure.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ROCCAT_COMMON2_BIN_ATTRIBUTE_R(tcu_image, 0x0c, 0x0404);
4747
ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0x0f, 0x06);
4848
ROCCAT_COMMON2_BIN_ATTRIBUTE_W(talk, 0x10, 0x10);
4949

50-
static struct bin_attribute *konepure_bin_attrs[] = {
50+
static const struct bin_attribute *const konepure_bin_attrs[] = {
5151
&bin_attr_actual_profile,
5252
&bin_attr_control,
5353
&bin_attr_info,
@@ -62,7 +62,7 @@ static struct bin_attribute *konepure_bin_attrs[] = {
6262
};
6363

6464
static const struct attribute_group konepure_group = {
65-
.bin_attrs = konepure_bin_attrs,
65+
.bin_attrs_new = konepure_bin_attrs,
6666
};
6767

6868
static const struct attribute_group *konepure_groups[] = {

drivers/hid/hid-roccat-ryos.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(stored_lights, 0x17, 0x0566);
4747
ROCCAT_COMMON2_BIN_ATTRIBUTE_W(custom_lights, 0x18, 0x14);
4848
ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(light_macro, 0x19, 0x07d2);
4949

50-
static struct bin_attribute *ryos_bin_attrs[] = {
50+
static const struct bin_attribute *const ryos_bin_attrs[] = {
5151
&bin_attr_control,
5252
&bin_attr_profile,
5353
&bin_attr_keys_primary,
@@ -70,7 +70,7 @@ static struct bin_attribute *ryos_bin_attrs[] = {
7070
};
7171

7272
static const struct attribute_group ryos_group = {
73-
.bin_attrs = ryos_bin_attrs,
73+
.bin_attrs_new = ryos_bin_attrs,
7474
};
7575

7676
static const struct attribute_group *ryos_groups[] = {

drivers/hid/hid-roccat-savu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(macro, 0x8, 0x0823);
3030
ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info, 0x9, 0x08);
3131
ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0xc, 0x04);
3232

33-
static struct bin_attribute *savu_bin_attrs[] = {
33+
static const struct bin_attribute *const savu_bin_attrs[] = {
3434
&bin_attr_control,
3535
&bin_attr_profile,
3636
&bin_attr_general,
@@ -42,7 +42,7 @@ static struct bin_attribute *savu_bin_attrs[] = {
4242
};
4343

4444
static const struct attribute_group savu_group = {
45-
.bin_attrs = savu_bin_attrs,
45+
.bin_attrs_new = savu_bin_attrs,
4646
};
4747

4848
static const struct attribute_group *savu_groups[] = {

0 commit comments

Comments
 (0)