Skip to content

Commit 06a9ceb

Browse files
t-8chmartinkpetersen
authored andcommitted
scsi: qla2xxx: 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-10-f0a5e54b3437@weissschuh.net Signed-off-by: Martin K. Petersen <[email protected]>
1 parent f9d0a84 commit 06a9ceb

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

drivers/scsi/qla2xxx/qla_attr.c

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static int qla24xx_vport_disable(struct fc_vport *, bool);
1717

1818
static ssize_t
1919
qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
20-
struct bin_attribute *bin_attr,
20+
const struct bin_attribute *bin_attr,
2121
char *buf, loff_t off, size_t count)
2222
{
2323
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -58,7 +58,7 @@ qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
5858

5959
static ssize_t
6060
qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
61-
struct bin_attribute *bin_attr,
61+
const struct bin_attribute *bin_attr,
6262
char *buf, loff_t off, size_t count)
6363
{
6464
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -168,19 +168,19 @@ qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
168168
return count;
169169
}
170170

171-
static struct bin_attribute sysfs_fw_dump_attr = {
171+
static const struct bin_attribute sysfs_fw_dump_attr = {
172172
.attr = {
173173
.name = "fw_dump",
174174
.mode = S_IRUSR | S_IWUSR,
175175
},
176176
.size = 0,
177-
.read = qla2x00_sysfs_read_fw_dump,
178-
.write = qla2x00_sysfs_write_fw_dump,
177+
.read_new = qla2x00_sysfs_read_fw_dump,
178+
.write_new = qla2x00_sysfs_write_fw_dump,
179179
};
180180

181181
static ssize_t
182182
qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
183-
struct bin_attribute *bin_attr,
183+
const struct bin_attribute *bin_attr,
184184
char *buf, loff_t off, size_t count)
185185
{
186186
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -220,7 +220,7 @@ qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
220220

221221
static ssize_t
222222
qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
223-
struct bin_attribute *bin_attr,
223+
const struct bin_attribute *bin_attr,
224224
char *buf, loff_t off, size_t count)
225225
{
226226
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -282,19 +282,19 @@ qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
282282
return count;
283283
}
284284

285-
static struct bin_attribute sysfs_nvram_attr = {
285+
static const struct bin_attribute sysfs_nvram_attr = {
286286
.attr = {
287287
.name = "nvram",
288288
.mode = S_IRUSR | S_IWUSR,
289289
},
290290
.size = 512,
291-
.read = qla2x00_sysfs_read_nvram,
292-
.write = qla2x00_sysfs_write_nvram,
291+
.read_new = qla2x00_sysfs_read_nvram,
292+
.write_new = qla2x00_sysfs_write_nvram,
293293
};
294294

295295
static ssize_t
296296
qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
297-
struct bin_attribute *bin_attr,
297+
const struct bin_attribute *bin_attr,
298298
char *buf, loff_t off, size_t count)
299299
{
300300
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -318,7 +318,7 @@ qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
318318

319319
static ssize_t
320320
qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
321-
struct bin_attribute *bin_attr,
321+
const struct bin_attribute *bin_attr,
322322
char *buf, loff_t off, size_t count)
323323
{
324324
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -344,19 +344,19 @@ qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
344344
return count;
345345
}
346346

347-
static struct bin_attribute sysfs_optrom_attr = {
347+
static const struct bin_attribute sysfs_optrom_attr = {
348348
.attr = {
349349
.name = "optrom",
350350
.mode = S_IRUSR | S_IWUSR,
351351
},
352352
.size = 0,
353-
.read = qla2x00_sysfs_read_optrom,
354-
.write = qla2x00_sysfs_write_optrom,
353+
.read_new = qla2x00_sysfs_read_optrom,
354+
.write_new = qla2x00_sysfs_write_optrom,
355355
};
356356

357357
static ssize_t
358358
qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
359-
struct bin_attribute *bin_attr,
359+
const struct bin_attribute *bin_attr,
360360
char *buf, loff_t off, size_t count)
361361
{
362362
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -529,18 +529,18 @@ qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
529529
return rval;
530530
}
531531

532-
static struct bin_attribute sysfs_optrom_ctl_attr = {
532+
static const struct bin_attribute sysfs_optrom_ctl_attr = {
533533
.attr = {
534534
.name = "optrom_ctl",
535535
.mode = S_IWUSR,
536536
},
537537
.size = 0,
538-
.write = qla2x00_sysfs_write_optrom_ctl,
538+
.write_new = qla2x00_sysfs_write_optrom_ctl,
539539
};
540540

541541
static ssize_t
542542
qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
543-
struct bin_attribute *bin_attr,
543+
const struct bin_attribute *bin_attr,
544544
char *buf, loff_t off, size_t count)
545545
{
546546
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -587,7 +587,7 @@ qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
587587

588588
static ssize_t
589589
qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
590-
struct bin_attribute *bin_attr,
590+
const struct bin_attribute *bin_attr,
591591
char *buf, loff_t off, size_t count)
592592
{
593593
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -642,19 +642,19 @@ qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
642642
return count;
643643
}
644644

645-
static struct bin_attribute sysfs_vpd_attr = {
645+
static const struct bin_attribute sysfs_vpd_attr = {
646646
.attr = {
647647
.name = "vpd",
648648
.mode = S_IRUSR | S_IWUSR,
649649
},
650650
.size = 0,
651-
.read = qla2x00_sysfs_read_vpd,
652-
.write = qla2x00_sysfs_write_vpd,
651+
.read_new = qla2x00_sysfs_read_vpd,
652+
.write_new = qla2x00_sysfs_write_vpd,
653653
};
654654

655655
static ssize_t
656656
qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
657-
struct bin_attribute *bin_attr,
657+
const struct bin_attribute *bin_attr,
658658
char *buf, loff_t off, size_t count)
659659
{
660660
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -679,18 +679,18 @@ qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
679679
return count;
680680
}
681681

682-
static struct bin_attribute sysfs_sfp_attr = {
682+
static const struct bin_attribute sysfs_sfp_attr = {
683683
.attr = {
684684
.name = "sfp",
685685
.mode = S_IRUSR | S_IWUSR,
686686
},
687687
.size = SFP_DEV_SIZE,
688-
.read = qla2x00_sysfs_read_sfp,
688+
.read_new = qla2x00_sysfs_read_sfp,
689689
};
690690

691691
static ssize_t
692692
qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
693-
struct bin_attribute *bin_attr,
693+
const struct bin_attribute *bin_attr,
694694
char *buf, loff_t off, size_t count)
695695
{
696696
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -823,19 +823,19 @@ qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
823823
return count;
824824
}
825825

826-
static struct bin_attribute sysfs_reset_attr = {
826+
static const struct bin_attribute sysfs_reset_attr = {
827827
.attr = {
828828
.name = "reset",
829829
.mode = S_IWUSR,
830830
},
831831
.size = 0,
832-
.write = qla2x00_sysfs_write_reset,
832+
.write_new = qla2x00_sysfs_write_reset,
833833
};
834834

835835
static ssize_t
836836
qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
837-
struct bin_attribute *bin_attr,
838-
char *buf, loff_t off, size_t count)
837+
const struct bin_attribute *bin_attr,
838+
char *buf, loff_t off, size_t count)
839839
{
840840
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
841841
struct device, kobj)));
@@ -866,18 +866,18 @@ qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
866866
return count;
867867
}
868868

869-
static struct bin_attribute sysfs_issue_logo_attr = {
869+
static const struct bin_attribute sysfs_issue_logo_attr = {
870870
.attr = {
871871
.name = "issue_logo",
872872
.mode = S_IWUSR,
873873
},
874874
.size = 0,
875-
.write = qla2x00_issue_logo,
875+
.write_new = qla2x00_issue_logo,
876876
};
877877

878878
static ssize_t
879879
qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
880-
struct bin_attribute *bin_attr,
880+
const struct bin_attribute *bin_attr,
881881
char *buf, loff_t off, size_t count)
882882
{
883883
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -929,18 +929,18 @@ qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
929929
return count;
930930
}
931931

932-
static struct bin_attribute sysfs_xgmac_stats_attr = {
932+
static const struct bin_attribute sysfs_xgmac_stats_attr = {
933933
.attr = {
934934
.name = "xgmac_stats",
935935
.mode = S_IRUSR,
936936
},
937937
.size = 0,
938-
.read = qla2x00_sysfs_read_xgmac_stats,
938+
.read_new = qla2x00_sysfs_read_xgmac_stats,
939939
};
940940

941941
static ssize_t
942942
qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
943-
struct bin_attribute *bin_attr,
943+
const struct bin_attribute *bin_attr,
944944
char *buf, loff_t off, size_t count)
945945
{
946946
struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
@@ -987,18 +987,18 @@ qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
987987
return count;
988988
}
989989

990-
static struct bin_attribute sysfs_dcbx_tlv_attr = {
990+
static const struct bin_attribute sysfs_dcbx_tlv_attr = {
991991
.attr = {
992992
.name = "dcbx_tlv",
993993
.mode = S_IRUSR,
994994
},
995995
.size = 0,
996-
.read = qla2x00_sysfs_read_dcbx_tlv,
996+
.read_new = qla2x00_sysfs_read_dcbx_tlv,
997997
};
998998

999999
static struct sysfs_entry {
10001000
char *name;
1001-
struct bin_attribute *attr;
1001+
const struct bin_attribute *attr;
10021002
int type;
10031003
} bin_file_entries[] = {
10041004
{ "fw_dump", &sysfs_fw_dump_attr, },

0 commit comments

Comments
 (0)