]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
accel/habanalabs: constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 16 Dec 2024 12:25:12 +0000 (13:25 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Feb 2025 08:20:31 +0000 (09:20 +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>
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Link: https://lore.kernel.org/r/20241216-sysfs-const-bin_attr-habanalabs-v1-1-b35463197efb@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/accel/habanalabs/common/sysfs.c

index e9f8ccc0bbf9d4dabec1b51072d07170c51ffc9e..9d58efa2ff380c8773bd79bea613dc79a5a98020 100644 (file)
@@ -368,7 +368,7 @@ out:
 }
 
 static ssize_t eeprom_read_handler(struct file *filp, struct kobject *kobj,
-                       struct bin_attribute *attr, char *buf, loff_t offset,
+                       const struct bin_attribute *attr, char *buf, loff_t offset,
                        size_t max_size)
 {
        struct device *dev = kobj_to_dev(kobj);
@@ -443,10 +443,10 @@ static DEVICE_ATTR_RO(security_enabled);
 static DEVICE_ATTR_RO(module_id);
 static DEVICE_ATTR_RO(parent_device);
 
-static struct bin_attribute bin_attr_eeprom = {
+static const struct bin_attribute bin_attr_eeprom = {
        .attr = {.name = "eeprom", .mode = (0444)},
        .size = PAGE_SIZE,
-       .read = eeprom_read_handler
+       .read_new = eeprom_read_handler
 };
 
 static struct attribute *hl_dev_attrs[] = {
@@ -472,14 +472,14 @@ static struct attribute *hl_dev_attrs[] = {
        NULL,
 };
 
-static struct bin_attribute *hl_dev_bin_attrs[] = {
+static const struct bin_attribute *const hl_dev_bin_attrs[] = {
        &bin_attr_eeprom,
        NULL
 };
 
 static struct attribute_group hl_dev_attr_group = {
        .attrs = hl_dev_attrs,
-       .bin_attrs = hl_dev_bin_attrs,
+       .bin_attrs_new = hl_dev_bin_attrs,
 };
 
 static struct attribute_group hl_dev_clks_attr_group;