Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/chrome: cros_ec_vbc: 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 <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20241215-sysfs-const-bin_attr-chrome-v1-1-92249c4bc295@weissschuh.net
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

authored by

Thomas Weißschuh and committed by
Tzung-Bi Shih
6fcbc55a 033fceed

+5 -5
+5 -5
drivers/platform/chrome/cros_ec_vbc.c
··· 15 15 #define DRV_NAME "cros-ec-vbc" 16 16 17 17 static ssize_t vboot_context_read(struct file *filp, struct kobject *kobj, 18 - struct bin_attribute *att, char *buf, 18 + const struct bin_attribute *att, char *buf, 19 19 loff_t pos, size_t count) 20 20 { 21 21 struct device *dev = kobj_to_dev(kobj); ··· 59 59 } 60 60 61 61 static ssize_t vboot_context_write(struct file *filp, struct kobject *kobj, 62 - struct bin_attribute *attr, char *buf, 62 + const struct bin_attribute *attr, char *buf, 63 63 loff_t pos, size_t count) 64 64 { 65 65 struct device *dev = kobj_to_dev(kobj); ··· 99 99 return data_sz; 100 100 } 101 101 102 - static BIN_ATTR_RW(vboot_context, 16); 102 + static const BIN_ATTR_RW(vboot_context, 16); 103 103 104 - static struct bin_attribute *cros_ec_vbc_bin_attrs[] = { 104 + static const struct bin_attribute *const cros_ec_vbc_bin_attrs[] = { 105 105 &bin_attr_vboot_context, 106 106 NULL 107 107 }; 108 108 109 109 static const struct attribute_group cros_ec_vbc_attr_group = { 110 110 .name = "vbc", 111 - .bin_attrs = cros_ec_vbc_bin_attrs, 111 + .bin_attrs_new = cros_ec_vbc_bin_attrs, 112 112 }; 113 113 114 114 static int cros_ec_vbc_probe(struct platform_device *pd)