Skip to content

Commit 79ef5c3

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

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

drivers/hid/hid-roccat-kovaplus.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ static ssize_t kovaplus_sysfs_write(struct file *fp, struct kobject *kobj,
171171

172172
#define KOVAPLUS_SYSFS_W(thingy, THINGY) \
173173
static ssize_t kovaplus_sysfs_write_ ## thingy(struct file *fp, \
174-
struct kobject *kobj, struct bin_attribute *attr, char *buf, \
175-
loff_t off, size_t count) \
174+
struct kobject *kobj, const struct bin_attribute *attr, \
175+
char *buf, loff_t off, size_t count) \
176176
{ \
177177
return kovaplus_sysfs_write(fp, kobj, buf, off, count, \
178178
KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \
179179
}
180180

181181
#define KOVAPLUS_SYSFS_R(thingy, THINGY) \
182182
static ssize_t kovaplus_sysfs_read_ ## thingy(struct file *fp, \
183-
struct kobject *kobj, struct bin_attribute *attr, char *buf, \
184-
loff_t off, size_t count) \
183+
struct kobject *kobj, const struct bin_attribute *attr, \
184+
char *buf, loff_t off, size_t count) \
185185
{ \
186186
return kovaplus_sysfs_read(fp, kobj, buf, off, count, \
187187
KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \
@@ -193,28 +193,28 @@ KOVAPLUS_SYSFS_R(thingy, THINGY)
193193

194194
#define KOVAPLUS_BIN_ATTRIBUTE_RW(thingy, THINGY) \
195195
KOVAPLUS_SYSFS_RW(thingy, THINGY); \
196-
static struct bin_attribute bin_attr_##thingy = { \
196+
static const struct bin_attribute bin_attr_##thingy = { \
197197
.attr = { .name = #thingy, .mode = 0660 }, \
198198
.size = KOVAPLUS_SIZE_ ## THINGY, \
199-
.read = kovaplus_sysfs_read_ ## thingy, \
200-
.write = kovaplus_sysfs_write_ ## thingy \
199+
.read_new = kovaplus_sysfs_read_ ## thingy, \
200+
.write_new = kovaplus_sysfs_write_ ## thingy \
201201
}
202202

203203
#define KOVAPLUS_BIN_ATTRIBUTE_W(thingy, THINGY) \
204204
KOVAPLUS_SYSFS_W(thingy, THINGY); \
205-
static struct bin_attribute bin_attr_##thingy = { \
205+
static const struct bin_attribute bin_attr_##thingy = { \
206206
.attr = { .name = #thingy, .mode = 0220 }, \
207207
.size = KOVAPLUS_SIZE_ ## THINGY, \
208-
.write = kovaplus_sysfs_write_ ## thingy \
208+
.write_new = kovaplus_sysfs_write_ ## thingy \
209209
}
210210
KOVAPLUS_BIN_ATTRIBUTE_W(control, CONTROL);
211211
KOVAPLUS_BIN_ATTRIBUTE_RW(info, INFO);
212212
KOVAPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS);
213213
KOVAPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS);
214214

215215
static ssize_t kovaplus_sysfs_read_profilex_settings(struct file *fp,
216-
struct kobject *kobj, struct bin_attribute *attr, char *buf,
217-
loff_t off, size_t count)
216+
struct kobject *kobj, const struct bin_attribute *attr,
217+
char *buf, loff_t off, size_t count)
218218
{
219219
struct device *dev = kobj_to_dev(kobj)->parent->parent;
220220
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
@@ -231,8 +231,8 @@ static ssize_t kovaplus_sysfs_read_profilex_settings(struct file *fp,
231231
}
232232

233233
static ssize_t kovaplus_sysfs_read_profilex_buttons(struct file *fp,
234-
struct kobject *kobj, struct bin_attribute *attr, char *buf,
235-
loff_t off, size_t count)
234+
struct kobject *kobj, const struct bin_attribute *attr,
235+
char *buf, loff_t off, size_t count)
236236
{
237237
struct device *dev = kobj_to_dev(kobj)->parent->parent;
238238
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
@@ -249,16 +249,16 @@ static ssize_t kovaplus_sysfs_read_profilex_buttons(struct file *fp,
249249
}
250250

251251
#define PROFILE_ATTR(number) \
252-
static struct bin_attribute bin_attr_profile##number##_settings = { \
252+
static const struct bin_attribute bin_attr_profile##number##_settings = { \
253253
.attr = { .name = "profile" #number "_settings", .mode = 0440 }, \
254254
.size = KOVAPLUS_SIZE_PROFILE_SETTINGS, \
255-
.read = kovaplus_sysfs_read_profilex_settings, \
255+
.read_new = kovaplus_sysfs_read_profilex_settings, \
256256
.private = &profile_numbers[number-1], \
257257
}; \
258-
static struct bin_attribute bin_attr_profile##number##_buttons = { \
258+
static const struct bin_attribute bin_attr_profile##number##_buttons = { \
259259
.attr = { .name = "profile" #number "_buttons", .mode = 0440 }, \
260260
.size = KOVAPLUS_SIZE_PROFILE_BUTTONS, \
261-
.read = kovaplus_sysfs_read_profilex_buttons, \
261+
.read_new = kovaplus_sysfs_read_profilex_buttons, \
262262
.private = &profile_numbers[number-1], \
263263
};
264264
PROFILE_ATTR(1);
@@ -379,7 +379,7 @@ static struct attribute *kovaplus_attrs[] = {
379379
NULL,
380380
};
381381

382-
static struct bin_attribute *kovaplus_bin_attributes[] = {
382+
static const struct bin_attribute *const kovaplus_bin_attributes[] = {
383383
&bin_attr_control,
384384
&bin_attr_info,
385385
&bin_attr_profile_settings,
@@ -399,7 +399,7 @@ static struct bin_attribute *kovaplus_bin_attributes[] = {
399399

400400
static const struct attribute_group kovaplus_group = {
401401
.attrs = kovaplus_attrs,
402-
.bin_attrs = kovaplus_bin_attributes,
402+
.bin_attrs_new = kovaplus_bin_attributes,
403403
};
404404

405405
static const struct attribute_group *kovaplus_groups[] = {

0 commit comments

Comments
 (0)