]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cxl/port: Constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Tue, 14 Jan 2025 21:25:14 +0000 (22:25 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Feb 2025 08:20:30 +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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/20250114-sysfs-const-bin_attr-cxl-v1-1-5afa23fe2a52@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/cxl/port.c

index d2bfd1ff5492405be4324b4721308f8f2132496e..a35fc55528459813d45427401d22d359174aa6b6 100644 (file)
@@ -153,7 +153,7 @@ static int cxl_port_probe(struct device *dev)
 }
 
 static ssize_t CDAT_read(struct file *filp, struct kobject *kobj,
-                        struct bin_attribute *bin_attr, char *buf,
+                        const struct bin_attribute *bin_attr, char *buf,
                         loff_t offset, size_t count)
 {
        struct device *dev = kobj_to_dev(kobj);
@@ -170,7 +170,7 @@ static ssize_t CDAT_read(struct file *filp, struct kobject *kobj,
                                       port->cdat.length);
 }
 
-static BIN_ATTR_ADMIN_RO(CDAT, 0);
+static const BIN_ATTR_ADMIN_RO(CDAT, 0);
 
 static umode_t cxl_port_bin_attr_is_visible(struct kobject *kobj,
                                            const struct bin_attribute *attr, int i)
@@ -184,13 +184,13 @@ static umode_t cxl_port_bin_attr_is_visible(struct kobject *kobj,
        return 0;
 }
 
-static struct bin_attribute *cxl_cdat_bin_attributes[] = {
+static const struct bin_attribute *const cxl_cdat_bin_attributes[] = {
        &bin_attr_CDAT,
        NULL,
 };
 
-static struct attribute_group cxl_cdat_attribute_group = {
-       .bin_attrs = cxl_cdat_bin_attributes,
+static const struct attribute_group cxl_cdat_attribute_group = {
+       .bin_attrs_new = cxl_cdat_bin_attributes,
        .is_bin_visible = cxl_port_bin_attr_is_visible,
 };