Skip to content

Commit 61e2d41

Browse files
t-8chmartinkpetersen
authored andcommitted
scsi: esas2r: 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-4-f0a5e54b3437@weissschuh.net Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 3e72fc0 commit 61e2d41

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

drivers/scsi/esas2r/esas2r.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,11 +1411,11 @@ static inline void esas2r_comp_list_drain(struct esas2r_adapter *a,
14111411
}
14121412

14131413
/* sysfs handlers */
1414-
extern struct bin_attribute bin_attr_fw;
1415-
extern struct bin_attribute bin_attr_fs;
1416-
extern struct bin_attribute bin_attr_vda;
1417-
extern struct bin_attribute bin_attr_hw;
1418-
extern struct bin_attribute bin_attr_live_nvram;
1419-
extern struct bin_attribute bin_attr_default_nvram;
1414+
extern const struct bin_attribute bin_attr_fw;
1415+
extern const struct bin_attribute bin_attr_fs;
1416+
extern const struct bin_attribute bin_attr_vda;
1417+
extern const struct bin_attribute bin_attr_hw;
1418+
extern const struct bin_attribute bin_attr_live_nvram;
1419+
extern const struct bin_attribute bin_attr_default_nvram;
14201420

14211421
#endif /* ESAS2R_H */

drivers/scsi/esas2r/esas2r_main.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static struct esas2r_adapter *esas2r_adapter_from_kobj(struct kobject *kobj)
6666
}
6767

6868
static ssize_t read_fw(struct file *file, struct kobject *kobj,
69-
struct bin_attribute *attr,
69+
const struct bin_attribute *attr,
7070
char *buf, loff_t off, size_t count)
7171
{
7272
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -75,7 +75,7 @@ static ssize_t read_fw(struct file *file, struct kobject *kobj,
7575
}
7676

7777
static ssize_t write_fw(struct file *file, struct kobject *kobj,
78-
struct bin_attribute *attr,
78+
const struct bin_attribute *attr,
7979
char *buf, loff_t off, size_t count)
8080
{
8181
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -84,7 +84,7 @@ static ssize_t write_fw(struct file *file, struct kobject *kobj,
8484
}
8585

8686
static ssize_t read_fs(struct file *file, struct kobject *kobj,
87-
struct bin_attribute *attr,
87+
const struct bin_attribute *attr,
8888
char *buf, loff_t off, size_t count)
8989
{
9090
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -93,7 +93,7 @@ static ssize_t read_fs(struct file *file, struct kobject *kobj,
9393
}
9494

9595
static ssize_t write_fs(struct file *file, struct kobject *kobj,
96-
struct bin_attribute *attr,
96+
const struct bin_attribute *attr,
9797
char *buf, loff_t off, size_t count)
9898
{
9999
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -109,7 +109,7 @@ static ssize_t write_fs(struct file *file, struct kobject *kobj,
109109
}
110110

111111
static ssize_t read_vda(struct file *file, struct kobject *kobj,
112-
struct bin_attribute *attr,
112+
const struct bin_attribute *attr,
113113
char *buf, loff_t off, size_t count)
114114
{
115115
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -118,7 +118,7 @@ static ssize_t read_vda(struct file *file, struct kobject *kobj,
118118
}
119119

120120
static ssize_t write_vda(struct file *file, struct kobject *kobj,
121-
struct bin_attribute *attr,
121+
const struct bin_attribute *attr,
122122
char *buf, loff_t off, size_t count)
123123
{
124124
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -127,7 +127,7 @@ static ssize_t write_vda(struct file *file, struct kobject *kobj,
127127
}
128128

129129
static ssize_t read_live_nvram(struct file *file, struct kobject *kobj,
130-
struct bin_attribute *attr,
130+
const struct bin_attribute *attr,
131131
char *buf, loff_t off, size_t count)
132132
{
133133
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -138,7 +138,7 @@ static ssize_t read_live_nvram(struct file *file, struct kobject *kobj,
138138
}
139139

140140
static ssize_t write_live_nvram(struct file *file, struct kobject *kobj,
141-
struct bin_attribute *attr,
141+
const struct bin_attribute *attr,
142142
char *buf, loff_t off, size_t count)
143143
{
144144
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -158,7 +158,7 @@ static ssize_t write_live_nvram(struct file *file, struct kobject *kobj,
158158
}
159159

160160
static ssize_t read_default_nvram(struct file *file, struct kobject *kobj,
161-
struct bin_attribute *attr,
161+
const struct bin_attribute *attr,
162162
char *buf, loff_t off, size_t count)
163163
{
164164
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -169,7 +169,7 @@ static ssize_t read_default_nvram(struct file *file, struct kobject *kobj,
169169
}
170170

171171
static ssize_t read_hw(struct file *file, struct kobject *kobj,
172-
struct bin_attribute *attr,
172+
const struct bin_attribute *attr,
173173
char *buf, loff_t off, size_t count)
174174
{
175175
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -187,7 +187,7 @@ static ssize_t read_hw(struct file *file, struct kobject *kobj,
187187
}
188188

189189
static ssize_t write_hw(struct file *file, struct kobject *kobj,
190-
struct bin_attribute *attr,
190+
const struct bin_attribute *attr,
191191
char *buf, loff_t off, size_t count)
192192
{
193193
struct esas2r_adapter *a = esas2r_adapter_from_kobj(kobj);
@@ -211,23 +211,23 @@ static ssize_t write_hw(struct file *file, struct kobject *kobj,
211211
}
212212

213213
#define ESAS2R_RW_BIN_ATTR(_name) \
214-
struct bin_attribute bin_attr_ ## _name = { \
214+
const struct bin_attribute bin_attr_ ## _name = { \
215215
.attr = \
216216
{ .name = __stringify(_name), .mode = S_IRUSR | S_IWUSR }, \
217217
.size = 0, \
218-
.read = read_ ## _name, \
219-
.write = write_ ## _name }
218+
.read_new = read_ ## _name, \
219+
.write_new = write_ ## _name }
220220

221221
ESAS2R_RW_BIN_ATTR(fw);
222222
ESAS2R_RW_BIN_ATTR(fs);
223223
ESAS2R_RW_BIN_ATTR(vda);
224224
ESAS2R_RW_BIN_ATTR(hw);
225225
ESAS2R_RW_BIN_ATTR(live_nvram);
226226

227-
struct bin_attribute bin_attr_default_nvram = {
227+
const struct bin_attribute bin_attr_default_nvram = {
228228
.attr = { .name = "default_nvram", .mode = S_IRUGO },
229229
.size = 0,
230-
.read = read_default_nvram,
230+
.read_new = read_default_nvram,
231231
.write = NULL
232232
};
233233

0 commit comments

Comments
 (0)