]> www.infradead.org Git - users/willy/xarray.git/commitdiff
power: supply: ds2781: constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 2 Dec 2024 19:02:21 +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-3-f846430b8b66@weissschuh.net
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/ds2781_battery.c

index c4f8ccc687f919f58c85bae83d308b83297fc074..8a1f1f9835e09598dd9f9426e0b63a0c5a3b4cc1 100644 (file)
@@ -623,7 +623,7 @@ static ssize_t ds2781_set_pio_pin(struct device *dev,
 
 static ssize_t ds2781_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);
@@ -636,7 +636,7 @@ static ssize_t ds2781_read_param_eeprom_bin(struct file *filp,
 
 static ssize_t ds2781_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);
@@ -656,19 +656,19 @@ static ssize_t ds2781_write_param_eeprom_bin(struct file *filp,
        return count;
 }
 
-static struct bin_attribute ds2781_param_eeprom_bin_attr = {
+static const struct bin_attribute ds2781_param_eeprom_bin_attr = {
        .attr = {
                .name = "param_eeprom",
                .mode = S_IRUGO | S_IWUSR,
        },
        .size = DS2781_PARAM_EEPROM_SIZE,
-       .read = ds2781_read_param_eeprom_bin,
-       .write = ds2781_write_param_eeprom_bin,
+       .read_new = ds2781_read_param_eeprom_bin,
+       .write_new = ds2781_write_param_eeprom_bin,
 };
 
 static ssize_t ds2781_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);
@@ -682,7 +682,7 @@ static ssize_t ds2781_read_user_eeprom_bin(struct file *filp,
 
 static ssize_t ds2781_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);
@@ -702,14 +702,14 @@ static ssize_t ds2781_write_user_eeprom_bin(struct file *filp,
        return count;
 }
 
-static struct bin_attribute ds2781_user_eeprom_bin_attr = {
+static const struct bin_attribute ds2781_user_eeprom_bin_attr = {
        .attr = {
                .name = "user_eeprom",
                .mode = S_IRUGO | S_IWUSR,
        },
        .size = DS2781_USER_EEPROM_SIZE,
-       .read = ds2781_read_user_eeprom_bin,
-       .write = ds2781_write_user_eeprom_bin,
+       .read_new = ds2781_read_user_eeprom_bin,
+       .write_new = ds2781_write_user_eeprom_bin,
 };
 
 static DEVICE_ATTR(pmod_enabled, S_IRUGO | S_IWUSR, ds2781_get_pmod_enabled,
@@ -729,7 +729,7 @@ static struct attribute *ds2781_sysfs_attrs[] = {
        NULL
 };
 
-static struct bin_attribute *ds2781_sysfs_bin_attrs[] = {
+static const struct bin_attribute *const ds2781_sysfs_bin_attrs[] = {
        &ds2781_param_eeprom_bin_attr,
        &ds2781_user_eeprom_bin_attr,
        NULL,
@@ -737,7 +737,7 @@ static struct bin_attribute *ds2781_sysfs_bin_attrs[] = {
 
 static const struct attribute_group ds2781_sysfs_group = {
        .attrs = ds2781_sysfs_attrs,
-       .bin_attrs = ds2781_sysfs_bin_attrs,
+       .bin_attrs_new = ds2781_sysfs_bin_attrs,
 
 };