]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
platform/x86: dell_rbu: Constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 2 Dec 2024 19:38:33 +0000 (20:38 +0100)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 17 Dec 2024 11:12:49 +0000 (13:12 +0200)
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-pdx86-v1-2-9ab204c2a814@weissschuh.net
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/dell/dell_rbu.c

index 9f51e0fcab04e1c61ce68b90b754b6b43a741b58..e30ca325938cb604560a810e7d63f65b4b70964b 100644 (file)
@@ -475,7 +475,7 @@ static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count)
 }
 
 static ssize_t data_read(struct file *filp, struct kobject *kobj,
-                        struct bin_attribute *bin_attr,
+                        const struct bin_attribute *bin_attr,
                         char *buffer, loff_t pos, size_t count)
 {
        ssize_t ret_count = 0;
@@ -492,7 +492,7 @@ static ssize_t data_read(struct file *filp, struct kobject *kobj,
        spin_unlock(&rbu_data.lock);
        return ret_count;
 }
-static BIN_ATTR_RO(data, 0);
+static const BIN_ATTR_RO(data, 0);
 
 static void callbackfn_rbu(const struct firmware *fw, void *context)
 {
@@ -530,7 +530,7 @@ static void callbackfn_rbu(const struct firmware *fw, void *context)
 }
 
 static ssize_t image_type_read(struct file *filp, struct kobject *kobj,
-                              struct bin_attribute *bin_attr,
+                              const struct bin_attribute *bin_attr,
                               char *buffer, loff_t pos, size_t count)
 {
        int size = 0;
@@ -540,7 +540,7 @@ static ssize_t image_type_read(struct file *filp, struct kobject *kobj,
 }
 
 static ssize_t image_type_write(struct file *filp, struct kobject *kobj,
-                               struct bin_attribute *bin_attr,
+                               const struct bin_attribute *bin_attr,
                                char *buffer, loff_t pos, size_t count)
 {
        int rc = count;
@@ -597,10 +597,10 @@ static ssize_t image_type_write(struct file *filp, struct kobject *kobj,
 
        return rc;
 }
-static BIN_ATTR_RW(image_type, 0);
+static const BIN_ATTR_RW(image_type, 0);
 
 static ssize_t packet_size_read(struct file *filp, struct kobject *kobj,
-                               struct bin_attribute *bin_attr,
+                               const struct bin_attribute *bin_attr,
                                char *buffer, loff_t pos, size_t count)
 {
        int size = 0;
@@ -613,7 +613,7 @@ static ssize_t packet_size_read(struct file *filp, struct kobject *kobj,
 }
 
 static ssize_t packet_size_write(struct file *filp, struct kobject *kobj,
-                                struct bin_attribute *bin_attr,
+                                const struct bin_attribute *bin_attr,
                                 char *buffer, loff_t pos, size_t count)
 {
        unsigned long temp;
@@ -626,9 +626,9 @@ static ssize_t packet_size_write(struct file *filp, struct kobject *kobj,
        spin_unlock(&rbu_data.lock);
        return count;
 }
-static BIN_ATTR_RW(packet_size, 0);
+static const BIN_ATTR_RW(packet_size, 0);
 
-static struct bin_attribute *rbu_bin_attrs[] = {
+static const struct bin_attribute *const rbu_bin_attrs[] = {
        &bin_attr_data,
        &bin_attr_image_type,
        &bin_attr_packet_size,
@@ -636,7 +636,7 @@ static struct bin_attribute *rbu_bin_attrs[] = {
 };
 
 static const struct attribute_group rbu_group = {
-       .bin_attrs = rbu_bin_attrs,
+       .bin_attrs_new = rbu_bin_attrs,
 };
 
 static int __init dcdrbu_init(void)