]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
platform/chrome: cros_ec_vbc: Constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Sun, 15 Dec 2024 13:29:15 +0000 (14:29 +0100)
committerTzung-Bi Shih <tzungbi@kernel.org>
Mon, 30 Dec 2024 01:31:05 +0000 (01:31 +0000)
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/20241215-sysfs-const-bin_attr-chrome-v1-1-92249c4bc295@weissschuh.net
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
drivers/platform/chrome/cros_ec_vbc.c

index 7bdb489354c5d203d2f4af22214314f6ead12c4e..963c4db23055d8fd807ec72072b1ae0a95c1bbb0 100644 (file)
@@ -15,7 +15,7 @@
 #define DRV_NAME "cros-ec-vbc"
 
 static ssize_t vboot_context_read(struct file *filp, struct kobject *kobj,
-                                 struct bin_attribute *att, char *buf,
+                                 const struct bin_attribute *att, char *buf,
                                  loff_t pos, size_t count)
 {
        struct device *dev = kobj_to_dev(kobj);
@@ -59,7 +59,7 @@ static ssize_t vboot_context_read(struct file *filp, struct kobject *kobj,
 }
 
 static ssize_t vboot_context_write(struct file *filp, struct kobject *kobj,
-                                  struct bin_attribute *attr, char *buf,
+                                  const struct bin_attribute *attr, char *buf,
                                   loff_t pos, size_t count)
 {
        struct device *dev = kobj_to_dev(kobj);
@@ -99,16 +99,16 @@ static ssize_t vboot_context_write(struct file *filp, struct kobject *kobj,
        return data_sz;
 }
 
-static BIN_ATTR_RW(vboot_context, 16);
+static const BIN_ATTR_RW(vboot_context, 16);
 
-static struct bin_attribute *cros_ec_vbc_bin_attrs[] = {
+static const struct bin_attribute *const cros_ec_vbc_bin_attrs[] = {
        &bin_attr_vboot_context,
        NULL
 };
 
 static const struct attribute_group cros_ec_vbc_attr_group = {
        .name = "vbc",
-       .bin_attrs = cros_ec_vbc_bin_attrs,
+       .bin_attrs_new = cros_ec_vbc_bin_attrs,
 };
 
 static int cros_ec_vbc_probe(struct platform_device *pd)