power: supply: ds2780: constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 2 Dec 2024 19:02:20 +0000 (20:02 +0100)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Wed, 4 Dec 2024 21:19:13 +0000 (22:19 +0100)
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/20241202-sysfs-const-bin_attr-psy-v1-2-f846430b8b66@weissschuh.net
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/ds2780_battery.c

index 1e7f297f6cb181e6ab7dc8e47b638aa43db8db97..dd9ac7a3296716d8ab72db56c1d9c0e439c3b2a9 100644 (file)
@@ -621,7 +621,7 @@ static ssize_t ds2780_set_pio_pin(struct device *dev,
 
 static ssize_t ds2780_read_param_eeprom_bin(struct file *filp,
                                struct kobject *kobj,
-                               struct bin_attribute *bin_attr,
+                               const struct bin_attribute *bin_attr,
                                char *buf, loff_t off, size_t count)
 {
        struct device *dev = kobj_to_dev(kobj);
@@ -634,7 +634,7 @@ static ssize_t ds2780_read_param_eeprom_bin(struct file *filp,
 
 static ssize_t ds2780_write_param_eeprom_bin(struct file *filp,
                                struct kobject *kobj,
-                               struct bin_attribute *bin_attr,
+                               const struct bin_attribute *bin_attr,
                                char *buf, loff_t off, size_t count)
 {
        struct device *dev = kobj_to_dev(kobj);
@@ -654,19 +654,19 @@ static ssize_t ds2780_write_param_eeprom_bin(struct file *filp,
        return count;
 }
 
-static struct bin_attribute ds2780_param_eeprom_bin_attr = {
+static const struct bin_attribute ds2780_param_eeprom_bin_attr = {
        .attr = {
                .name = "param_eeprom",
                .mode = S_IRUGO | S_IWUSR,
        },
        .size = DS2780_PARAM_EEPROM_SIZE,
-       .read = ds2780_read_param_eeprom_bin,
-       .write = ds2780_write_param_eeprom_bin,
+       .read_new = ds2780_read_param_eeprom_bin,
+       .write_new = ds2780_write_param_eeprom_bin,
 };
 
 static ssize_t ds2780_read_user_eeprom_bin(struct file *filp,
                                struct kobject *kobj,
-                               struct bin_attribute *bin_attr,
+                               const struct bin_attribute *bin_attr,
                                char *buf, loff_t off, size_t count)
 {
        struct device *dev = kobj_to_dev(kobj);
@@ -679,7 +679,7 @@ static ssize_t ds2780_read_user_eeprom_bin(struct file *filp,
 
 static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
                                struct kobject *kobj,
-                               struct bin_attribute *bin_attr,
+                               const struct bin_attribute *bin_attr,
                                char *buf, loff_t off, size_t count)
 {
        struct device *dev = kobj_to_dev(kobj);
@@ -699,14 +699,14 @@ static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
        return count;
 }
 
-static struct bin_attribute ds2780_user_eeprom_bin_attr = {
+static const struct bin_attribute ds2780_user_eeprom_bin_attr = {
        .attr = {
                .name = "user_eeprom",
                .mode = S_IRUGO | S_IWUSR,
        },
        .size = DS2780_USER_EEPROM_SIZE,
-       .read = ds2780_read_user_eeprom_bin,
-       .write = ds2780_write_user_eeprom_bin,
+       .read_new = ds2780_read_user_eeprom_bin,
+       .write_new = ds2780_write_user_eeprom_bin,
 };
 
 static DEVICE_ATTR(pmod_enabled, S_IRUGO | S_IWUSR, ds2780_get_pmod_enabled,
@@ -726,7 +726,7 @@ static struct attribute *ds2780_sysfs_attrs[] = {
        NULL
 };
 
-static struct bin_attribute *ds2780_sysfs_bin_attrs[] = {
+static const struct bin_attribute *const ds2780_sysfs_bin_attrs[] = {
        &ds2780_param_eeprom_bin_attr,
        &ds2780_user_eeprom_bin_attr,
        NULL
@@ -734,7 +734,7 @@ static struct bin_attribute *ds2780_sysfs_bin_attrs[] = {
 
 static const struct attribute_group ds2780_sysfs_group = {
        .attrs = ds2780_sysfs_attrs,
-       .bin_attrs = ds2780_sysfs_bin_attrs,
+       .bin_attrs_new = ds2780_sysfs_bin_attrs,
 };
 
 static const struct attribute_group *ds2780_sysfs_groups[] = {