Skip to content

Commit e4dab5d

Browse files
t-8chmartinkpetersen
authored andcommitted
scsi: core: Constify 'struct bin_attribute'
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 <[email protected]> Link: https://lore.kernel.org/r/20241216-sysfs-const-bin_attr-scsi-v1-1-f0a5e54b3437@weissschuh.net Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 40384c8 commit e4dab5d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/scsi/scsi_sysfs.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ static DEVICE_ATTR(queue_type, S_IRUGO | S_IWUSR, show_queue_type_field,
898898
#define sdev_vpd_pg_attr(_page) \
899899
static ssize_t \
900900
show_vpd_##_page(struct file *filp, struct kobject *kobj, \
901-
struct bin_attribute *bin_attr, \
901+
const struct bin_attribute *bin_attr, \
902902
char *buf, loff_t off, size_t count) \
903903
{ \
904904
struct device *dev = kobj_to_dev(kobj); \
@@ -914,10 +914,10 @@ show_vpd_##_page(struct file *filp, struct kobject *kobj, \
914914
rcu_read_unlock(); \
915915
return ret; \
916916
} \
917-
static struct bin_attribute dev_attr_vpd_##_page = { \
917+
static const struct bin_attribute dev_attr_vpd_##_page = { \
918918
.attr = {.name = __stringify(vpd_##_page), .mode = S_IRUGO }, \
919919
.size = 0, \
920-
.read = show_vpd_##_page, \
920+
.read_new = show_vpd_##_page, \
921921
};
922922

923923
sdev_vpd_pg_attr(pg83);
@@ -930,7 +930,7 @@ sdev_vpd_pg_attr(pgb7);
930930
sdev_vpd_pg_attr(pg0);
931931

932932
static ssize_t show_inquiry(struct file *filep, struct kobject *kobj,
933-
struct bin_attribute *bin_attr,
933+
const struct bin_attribute *bin_attr,
934934
char *buf, loff_t off, size_t count)
935935
{
936936
struct device *dev = kobj_to_dev(kobj);
@@ -943,13 +943,13 @@ static ssize_t show_inquiry(struct file *filep, struct kobject *kobj,
943943
sdev->inquiry_len);
944944
}
945945

946-
static struct bin_attribute dev_attr_inquiry = {
946+
static const struct bin_attribute dev_attr_inquiry = {
947947
.attr = {
948948
.name = "inquiry",
949949
.mode = S_IRUGO,
950950
},
951951
.size = 0,
952-
.read = show_inquiry,
952+
.read_new = show_inquiry,
953953
};
954954

955955
static ssize_t
@@ -1348,7 +1348,7 @@ static struct attribute *scsi_sdev_attrs[] = {
13481348
NULL
13491349
};
13501350

1351-
static struct bin_attribute *scsi_sdev_bin_attrs[] = {
1351+
static const struct bin_attribute *const scsi_sdev_bin_attrs[] = {
13521352
&dev_attr_vpd_pg0,
13531353
&dev_attr_vpd_pg83,
13541354
&dev_attr_vpd_pg80,
@@ -1362,7 +1362,7 @@ static struct bin_attribute *scsi_sdev_bin_attrs[] = {
13621362
};
13631363
static struct attribute_group scsi_sdev_attr_group = {
13641364
.attrs = scsi_sdev_attrs,
1365-
.bin_attrs = scsi_sdev_bin_attrs,
1365+
.bin_attrs_new = scsi_sdev_bin_attrs,
13661366
.is_visible = scsi_sdev_attr_is_visible,
13671367
.is_bin_visible = scsi_sdev_bin_attr_is_visible,
13681368
};

0 commit comments

Comments
 (0)