Skip to content

Commit 4b02dcc

Browse files
t-8chJiri Kosina
authored andcommitted
HID: roccat: koneplus: 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 badcb32 commit 4b02dcc

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

drivers/hid/hid-roccat-koneplus.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,17 @@ static ssize_t koneplus_sysfs_write(struct file *fp, struct kobject *kobj,
128128

129129
#define KONEPLUS_SYSFS_W(thingy, THINGY) \
130130
static ssize_t koneplus_sysfs_write_ ## thingy(struct file *fp, \
131-
struct kobject *kobj, struct bin_attribute *attr, char *buf, \
132-
loff_t off, size_t count) \
131+
struct kobject *kobj, const struct bin_attribute *attr, \
132+
char *buf, loff_t off, size_t count) \
133133
{ \
134134
return koneplus_sysfs_write(fp, kobj, buf, off, count, \
135135
KONEPLUS_SIZE_ ## THINGY, KONEPLUS_COMMAND_ ## THINGY); \
136136
}
137137

138138
#define KONEPLUS_SYSFS_R(thingy, THINGY) \
139139
static ssize_t koneplus_sysfs_read_ ## thingy(struct file *fp, \
140-
struct kobject *kobj, struct bin_attribute *attr, char *buf, \
141-
loff_t off, size_t count) \
140+
struct kobject *kobj, const struct bin_attribute *attr, \
141+
char *buf, loff_t off, size_t count) \
142142
{ \
143143
return koneplus_sysfs_read(fp, kobj, buf, off, count, \
144144
KONEPLUS_SIZE_ ## THINGY, KONEPLUS_COMMAND_ ## THINGY); \
@@ -150,27 +150,27 @@ KONEPLUS_SYSFS_R(thingy, THINGY)
150150

151151
#define KONEPLUS_BIN_ATTRIBUTE_RW(thingy, THINGY) \
152152
KONEPLUS_SYSFS_RW(thingy, THINGY); \
153-
static struct bin_attribute bin_attr_##thingy = { \
153+
static const struct bin_attribute bin_attr_##thingy = { \
154154
.attr = { .name = #thingy, .mode = 0660 }, \
155155
.size = KONEPLUS_SIZE_ ## THINGY, \
156-
.read = koneplus_sysfs_read_ ## thingy, \
157-
.write = koneplus_sysfs_write_ ## thingy \
156+
.read_new = koneplus_sysfs_read_ ## thingy, \
157+
.write_new = koneplus_sysfs_write_ ## thingy \
158158
}
159159

160160
#define KONEPLUS_BIN_ATTRIBUTE_R(thingy, THINGY) \
161161
KONEPLUS_SYSFS_R(thingy, THINGY); \
162-
static struct bin_attribute bin_attr_##thingy = { \
162+
static const struct bin_attribute bin_attr_##thingy = { \
163163
.attr = { .name = #thingy, .mode = 0440 }, \
164164
.size = KONEPLUS_SIZE_ ## THINGY, \
165-
.read = koneplus_sysfs_read_ ## thingy, \
165+
.read_new = koneplus_sysfs_read_ ## thingy, \
166166
}
167167

168168
#define KONEPLUS_BIN_ATTRIBUTE_W(thingy, THINGY) \
169169
KONEPLUS_SYSFS_W(thingy, THINGY); \
170-
static struct bin_attribute bin_attr_##thingy = { \
170+
static const struct bin_attribute bin_attr_##thingy = { \
171171
.attr = { .name = #thingy, .mode = 0220 }, \
172172
.size = KONEPLUS_SIZE_ ## THINGY, \
173-
.write = koneplus_sysfs_write_ ## thingy \
173+
.write_new = koneplus_sysfs_write_ ## thingy \
174174
}
175175
KONEPLUS_BIN_ATTRIBUTE_W(control, CONTROL);
176176
KONEPLUS_BIN_ATTRIBUTE_W(talk, TALK);
@@ -183,8 +183,8 @@ KONEPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS);
183183
KONEPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS);
184184

185185
static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp,
186-
struct kobject *kobj, struct bin_attribute *attr, char *buf,
187-
loff_t off, size_t count)
186+
struct kobject *kobj, const struct bin_attribute *attr,
187+
char *buf, loff_t off, size_t count)
188188
{
189189
struct device *dev = kobj_to_dev(kobj)->parent->parent;
190190
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
@@ -201,8 +201,8 @@ static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp,
201201
}
202202

203203
static ssize_t koneplus_sysfs_read_profilex_buttons(struct file *fp,
204-
struct kobject *kobj, struct bin_attribute *attr, char *buf,
205-
loff_t off, size_t count)
204+
struct kobject *kobj, const struct bin_attribute *attr,
205+
char *buf, loff_t off, size_t count)
206206
{
207207
struct device *dev = kobj_to_dev(kobj)->parent->parent;
208208
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
@@ -219,16 +219,16 @@ static ssize_t koneplus_sysfs_read_profilex_buttons(struct file *fp,
219219
}
220220

221221
#define PROFILE_ATTR(number) \
222-
static struct bin_attribute bin_attr_profile##number##_settings = { \
222+
static const struct bin_attribute bin_attr_profile##number##_settings = { \
223223
.attr = { .name = "profile" #number "_settings", .mode = 0440 }, \
224224
.size = KONEPLUS_SIZE_PROFILE_SETTINGS, \
225-
.read = koneplus_sysfs_read_profilex_settings, \
225+
.read_new = koneplus_sysfs_read_profilex_settings, \
226226
.private = &profile_numbers[number-1], \
227227
}; \
228-
static struct bin_attribute bin_attr_profile##number##_buttons = { \
228+
static const struct bin_attribute bin_attr_profile##number##_buttons = { \
229229
.attr = { .name = "profile" #number "_buttons", .mode = 0440 }, \
230230
.size = KONEPLUS_SIZE_PROFILE_BUTTONS, \
231-
.read = koneplus_sysfs_read_profilex_buttons, \
231+
.read_new = koneplus_sysfs_read_profilex_buttons, \
232232
.private = &profile_numbers[number-1], \
233233
};
234234
PROFILE_ATTR(1);
@@ -321,7 +321,7 @@ static struct attribute *koneplus_attrs[] = {
321321
NULL,
322322
};
323323

324-
static struct bin_attribute *koneplus_bin_attributes[] = {
324+
static const struct bin_attribute *const koneplus_bin_attributes[] = {
325325
&bin_attr_control,
326326
&bin_attr_talk,
327327
&bin_attr_macro,
@@ -346,7 +346,7 @@ static struct bin_attribute *koneplus_bin_attributes[] = {
346346

347347
static const struct attribute_group koneplus_group = {
348348
.attrs = koneplus_attrs,
349-
.bin_attrs = koneplus_bin_attributes,
349+
.bin_attrs_new = koneplus_bin_attributes,
350350
};
351351

352352
static const struct attribute_group *koneplus_groups[] = {

0 commit comments

Comments
 (0)