Skip to content

Commit badcb32

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

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

drivers/hid/hid-roccat-kone.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static int kone_get_firmware_version(struct usb_device *usb_dev, int *result)
261261
}
262262

263263
static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj,
264-
struct bin_attribute *attr, char *buf,
264+
const struct bin_attribute *attr, char *buf,
265265
loff_t off, size_t count) {
266266
struct device *dev = kobj_to_dev(kobj)->parent->parent;
267267
struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
@@ -285,7 +285,7 @@ static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj,
285285
* case of error the old data is still valid
286286
*/
287287
static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj,
288-
struct bin_attribute *attr, char *buf,
288+
const struct bin_attribute *attr, char *buf,
289289
loff_t off, size_t count) {
290290
struct device *dev = kobj_to_dev(kobj)->parent->parent;
291291
struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
@@ -327,11 +327,11 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj,
327327

328328
return sizeof(struct kone_settings);
329329
}
330-
static BIN_ATTR(settings, 0660, kone_sysfs_read_settings,
331-
kone_sysfs_write_settings, sizeof(struct kone_settings));
330+
static const BIN_ATTR(settings, 0660, kone_sysfs_read_settings,
331+
kone_sysfs_write_settings, sizeof(struct kone_settings));
332332

333333
static ssize_t kone_sysfs_read_profilex(struct file *fp,
334-
struct kobject *kobj, struct bin_attribute *attr,
334+
struct kobject *kobj, const struct bin_attribute *attr,
335335
char *buf, loff_t off, size_t count) {
336336
struct device *dev = kobj_to_dev(kobj)->parent->parent;
337337
struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
@@ -351,7 +351,7 @@ static ssize_t kone_sysfs_read_profilex(struct file *fp,
351351

352352
/* Writes data only if different to stored data */
353353
static ssize_t kone_sysfs_write_profilex(struct file *fp,
354-
struct kobject *kobj, struct bin_attribute *attr,
354+
struct kobject *kobj, const struct bin_attribute *attr,
355355
char *buf, loff_t off, size_t count) {
356356
struct device *dev = kobj_to_dev(kobj)->parent->parent;
357357
struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev));
@@ -382,11 +382,11 @@ static ssize_t kone_sysfs_write_profilex(struct file *fp,
382382
return sizeof(struct kone_profile);
383383
}
384384
#define PROFILE_ATTR(number) \
385-
static struct bin_attribute bin_attr_profile##number = { \
385+
static const struct bin_attribute bin_attr_profile##number = { \
386386
.attr = { .name = "profile" #number, .mode = 0660 }, \
387387
.size = sizeof(struct kone_profile), \
388-
.read = kone_sysfs_read_profilex, \
389-
.write = kone_sysfs_write_profilex, \
388+
.read_new = kone_sysfs_read_profilex, \
389+
.write_new = kone_sysfs_write_profilex, \
390390
.private = &profile_numbers[number-1], \
391391
}
392392
PROFILE_ATTR(1);
@@ -634,7 +634,7 @@ static struct attribute *kone_attrs[] = {
634634
NULL,
635635
};
636636

637-
static struct bin_attribute *kone_bin_attributes[] = {
637+
static const struct bin_attribute *const kone_bin_attributes[] = {
638638
&bin_attr_settings,
639639
&bin_attr_profile1,
640640
&bin_attr_profile2,
@@ -646,7 +646,7 @@ static struct bin_attribute *kone_bin_attributes[] = {
646646

647647
static const struct attribute_group kone_group = {
648648
.attrs = kone_attrs,
649-
.bin_attrs = kone_bin_attributes,
649+
.bin_attrs_new = kone_bin_attributes,
650650
};
651651

652652
static const struct attribute_group *kone_groups[] = {

0 commit comments

Comments
 (0)