scsi: lpfc: Constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 16 Dec 2024 11:29:13 +0000 (12:29 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 2 Jan 2025 20:07:45 +0000 (15:07 -0500)
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/20241216-sysfs-const-bin_attr-scsi-v1-6-f0a5e54b3437@weissschuh.net
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/lpfc/lpfc_attr.c

index 39b504164ecc187d8b0798c95c9fa3f6bc9780e3..0d0213bba35da8e10be8b874763dd5f01d6ff586 100644 (file)
@@ -6185,7 +6185,7 @@ const struct attribute_group *lpfc_vport_groups[] = {
  **/
 static ssize_t
 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
-                  struct bin_attribute *bin_attr,
+                  const struct bin_attribute *bin_attr,
                   char *buf, loff_t off, size_t count)
 {
        size_t buf_off;
@@ -6244,7 +6244,7 @@ sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
  **/
 static ssize_t
 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
-                 struct bin_attribute *bin_attr,
+                 const struct bin_attribute *bin_attr,
                  char *buf, loff_t off, size_t count)
 {
        size_t buf_off;
@@ -6280,14 +6280,14 @@ sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
        return count;
 }
 
-static struct bin_attribute sysfs_ctlreg_attr = {
+static const struct bin_attribute sysfs_ctlreg_attr = {
        .attr = {
                .name = "ctlreg",
                .mode = S_IRUSR | S_IWUSR,
        },
        .size = 256,
-       .read = sysfs_ctlreg_read,
-       .write = sysfs_ctlreg_write,
+       .read_new = sysfs_ctlreg_read,
+       .write_new = sysfs_ctlreg_write,
 };
 
 /**
@@ -6308,7 +6308,7 @@ static struct bin_attribute sysfs_ctlreg_attr = {
  **/
 static ssize_t
 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
-                struct bin_attribute *bin_attr,
+                const struct bin_attribute *bin_attr,
                 char *buf, loff_t off, size_t count)
 {
        return -EPERM;
@@ -6332,20 +6332,20 @@ sysfs_mbox_write(struct file *filp, struct kobject *kobj,
  **/
 static ssize_t
 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
-               struct bin_attribute *bin_attr,
+               const struct bin_attribute *bin_attr,
                char *buf, loff_t off, size_t count)
 {
        return -EPERM;
 }
 
-static struct bin_attribute sysfs_mbox_attr = {
+static const struct bin_attribute sysfs_mbox_attr = {
        .attr = {
                .name = "mbox",
                .mode = S_IRUSR | S_IWUSR,
        },
        .size = MAILBOX_SYSFS_MAX,
-       .read = sysfs_mbox_read,
-       .write = sysfs_mbox_write,
+       .read_new = sysfs_mbox_read,
+       .write_new = sysfs_mbox_write,
 };
 
 /**