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

misc: c2port: 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/20241221-sysfs-const-bin_attr-misc-drivers-v2-5-ba5e79fe8771@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Weißschuh and committed by
Greg Kroah-Hartman
fc58d178 85aa1342

+6 -6
+6 -6
drivers/misc/c2port/core.c
··· 714 714 } 715 715 716 716 static ssize_t c2port_read_flash_data(struct file *filp, struct kobject *kobj, 717 - struct bin_attribute *attr, 717 + const struct bin_attribute *attr, 718 718 char *buffer, loff_t offset, size_t count) 719 719 { 720 720 struct c2port_device *c2dev = dev_get_drvdata(kobj_to_dev(kobj)); ··· 829 829 } 830 830 831 831 static ssize_t c2port_write_flash_data(struct file *filp, struct kobject *kobj, 832 - struct bin_attribute *attr, 832 + const struct bin_attribute *attr, 833 833 char *buffer, loff_t offset, size_t count) 834 834 { 835 835 struct c2port_device *c2dev = dev_get_drvdata(kobj_to_dev(kobj)); ··· 849 849 return ret; 850 850 } 851 851 /* size is computed at run-time */ 852 - static BIN_ATTR(flash_data, 0644, c2port_read_flash_data, 853 - c2port_write_flash_data, 0); 852 + static const BIN_ATTR(flash_data, 0644, c2port_read_flash_data, 853 + c2port_write_flash_data, 0); 854 854 855 855 /* 856 856 * Class attributes ··· 869 869 NULL, 870 870 }; 871 871 872 - static struct bin_attribute *c2port_bin_attrs[] = { 872 + static const struct bin_attribute *const c2port_bin_attrs[] = { 873 873 &bin_attr_flash_data, 874 874 NULL, 875 875 }; ··· 888 888 889 889 static const struct attribute_group c2port_group = { 890 890 .attrs = c2port_attrs, 891 - .bin_attrs = c2port_bin_attrs, 891 + .bin_attrs_new = c2port_bin_attrs, 892 892 .bin_size = c2port_bin_attr_size, 893 893 }; 894 894