]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
i2c: slave-eeprom: Constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Sun, 15 Dec 2024 13:21:39 +0000 (14:21 +0100)
committerWolfram Sang <wsa+renesas@sang-engineering.com>
Thu, 9 Jan 2025 09:48:44 +0000 (10:48 +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>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
drivers/i2c/i2c-slave-eeprom.c

index 5946c0d0aef991aaa280a2df1d74d8a2ef09120f..275d1d0e910fbec72c4795cb3aafa714c52fcd94 100644 (file)
@@ -91,7 +91,7 @@ static int i2c_slave_eeprom_slave_cb(struct i2c_client *client,
 }
 
 static ssize_t i2c_slave_eeprom_bin_read(struct file *filp, struct kobject *kobj,
-               struct bin_attribute *attr, char *buf, loff_t off, size_t count)
+               const struct bin_attribute *attr, char *buf, loff_t off, size_t count)
 {
        struct eeprom_data *eeprom;
        unsigned long flags;
@@ -106,7 +106,7 @@ static ssize_t i2c_slave_eeprom_bin_read(struct file *filp, struct kobject *kobj
 }
 
 static ssize_t i2c_slave_eeprom_bin_write(struct file *filp, struct kobject *kobj,
-               struct bin_attribute *attr, char *buf, loff_t off, size_t count)
+               const struct bin_attribute *attr, char *buf, loff_t off, size_t count)
 {
        struct eeprom_data *eeprom;
        unsigned long flags;
@@ -165,8 +165,8 @@ static int i2c_slave_eeprom_probe(struct i2c_client *client)
        sysfs_bin_attr_init(&eeprom->bin);
        eeprom->bin.attr.name = "slave-eeprom";
        eeprom->bin.attr.mode = S_IRUSR | S_IWUSR;
-       eeprom->bin.read = i2c_slave_eeprom_bin_read;
-       eeprom->bin.write = i2c_slave_eeprom_bin_write;
+       eeprom->bin.read_new = i2c_slave_eeprom_bin_read;
+       eeprom->bin.write_new = i2c_slave_eeprom_bin_write;
        eeprom->bin.size = size;
 
        ret = sysfs_create_bin_file(&client->dev.kobj, &eeprom->bin);