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

ptp: ocp: 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>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Link: https://patch.msgid.link/20241222-sysfs-const-bin_attr-ptp-v1-1-5c1f3ee246fb@weissschuh.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Thomas Weißschuh and committed by
Jakub Kicinski
be16b46f c83ca5a4

+8 -8
+8 -8
drivers/ptp/ptp_ocp.c
··· 3692 3692 3693 3693 static ssize_t 3694 3694 disciplining_config_read(struct file *filp, struct kobject *kobj, 3695 - struct bin_attribute *bin_attr, char *buf, 3695 + const struct bin_attribute *bin_attr, char *buf, 3696 3696 loff_t off, size_t count) 3697 3697 { 3698 3698 struct ptp_ocp *bp = dev_get_drvdata(kobj_to_dev(kobj)); ··· 3727 3727 3728 3728 static ssize_t 3729 3729 disciplining_config_write(struct file *filp, struct kobject *kobj, 3730 - struct bin_attribute *bin_attr, char *buf, 3730 + const struct bin_attribute *bin_attr, char *buf, 3731 3731 loff_t off, size_t count) 3732 3732 { 3733 3733 struct ptp_ocp *bp = dev_get_drvdata(kobj_to_dev(kobj)); ··· 3750 3750 3751 3751 return err; 3752 3752 } 3753 - static BIN_ATTR_RW(disciplining_config, OCP_ART_CONFIG_SIZE); 3753 + static const BIN_ATTR_RW(disciplining_config, OCP_ART_CONFIG_SIZE); 3754 3754 3755 3755 static ssize_t 3756 3756 temperature_table_read(struct file *filp, struct kobject *kobj, 3757 - struct bin_attribute *bin_attr, char *buf, 3757 + const struct bin_attribute *bin_attr, char *buf, 3758 3758 loff_t off, size_t count) 3759 3759 { 3760 3760 struct ptp_ocp *bp = dev_get_drvdata(kobj_to_dev(kobj)); ··· 3789 3789 3790 3790 static ssize_t 3791 3791 temperature_table_write(struct file *filp, struct kobject *kobj, 3792 - struct bin_attribute *bin_attr, char *buf, 3792 + const struct bin_attribute *bin_attr, char *buf, 3793 3793 loff_t off, size_t count) 3794 3794 { 3795 3795 struct ptp_ocp *bp = dev_get_drvdata(kobj_to_dev(kobj)); ··· 3812 3812 3813 3813 return err; 3814 3814 } 3815 - static BIN_ATTR_RW(temperature_table, OCP_ART_TEMP_TABLE_SIZE); 3815 + static const BIN_ATTR_RW(temperature_table, OCP_ART_TEMP_TABLE_SIZE); 3816 3816 3817 3817 static struct attribute *fb_timecard_attrs[] = { 3818 3818 &dev_attr_serialnum.attr, ··· 3867 3867 NULL, 3868 3868 }; 3869 3869 3870 - static struct bin_attribute *bin_art_timecard_attrs[] = { 3870 + static const struct bin_attribute *const bin_art_timecard_attrs[] = { 3871 3871 &bin_attr_disciplining_config, 3872 3872 &bin_attr_temperature_table, 3873 3873 NULL, ··· 3875 3875 3876 3876 static const struct attribute_group art_timecard_group = { 3877 3877 .attrs = art_timecard_attrs, 3878 - .bin_attrs = bin_art_timecard_attrs, 3878 + .bin_attrs_new = bin_art_timecard_attrs, 3879 3879 }; 3880 3880 3881 3881 static const struct ocp_attr_group art_timecard_groups[] = {