Skip to content

Commit f5f01c5

Browse files
t-8chrleon
authored andcommitted
RDMA/qib: 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://patch.msgid.link/20250114-sysfs-const-bin_attr-infiniband-v1-2-397aaa94d453@weissschuh.net Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 39d772f commit f5f01c5

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/infiniband/hw/qib/qib_sysfs.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ static const struct attribute_group port_linkcontrol_group = {
214214
* Congestion control table size followed by table entries
215215
*/
216216
static ssize_t cc_table_bin_read(struct file *filp, struct kobject *kobj,
217-
struct bin_attribute *bin_attr, char *buf,
218-
loff_t pos, size_t count)
217+
const struct bin_attribute *bin_attr,
218+
char *buf, loff_t pos, size_t count)
219219
{
220220
struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj);
221221
int ret;
@@ -241,16 +241,16 @@ static ssize_t cc_table_bin_read(struct file *filp, struct kobject *kobj,
241241

242242
return count;
243243
}
244-
static BIN_ATTR_RO(cc_table_bin, PAGE_SIZE);
244+
static const BIN_ATTR_RO(cc_table_bin, PAGE_SIZE);
245245

246246
/*
247247
* Congestion settings: port control, control map and an array of 16
248248
* entries for the congestion entries - increase, timer, event log
249249
* trigger threshold and the minimum injection rate delay.
250250
*/
251251
static ssize_t cc_setting_bin_read(struct file *filp, struct kobject *kobj,
252-
struct bin_attribute *bin_attr, char *buf,
253-
loff_t pos, size_t count)
252+
const struct bin_attribute *bin_attr,
253+
char *buf, loff_t pos, size_t count)
254254
{
255255
struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj);
256256
int ret;
@@ -274,9 +274,9 @@ static ssize_t cc_setting_bin_read(struct file *filp, struct kobject *kobj,
274274

275275
return count;
276276
}
277-
static BIN_ATTR_RO(cc_setting_bin, PAGE_SIZE);
277+
static const BIN_ATTR_RO(cc_setting_bin, PAGE_SIZE);
278278

279-
static struct bin_attribute *port_ccmgta_attributes[] = {
279+
static const struct bin_attribute *const port_ccmgta_attributes[] = {
280280
&bin_attr_cc_setting_bin,
281281
&bin_attr_cc_table_bin,
282282
NULL,
@@ -295,7 +295,7 @@ static umode_t qib_ccmgta_is_bin_visible(struct kobject *kobj,
295295
static const struct attribute_group port_ccmgta_attribute_group = {
296296
.name = "CCMgtA",
297297
.is_bin_visible = qib_ccmgta_is_bin_visible,
298-
.bin_attrs = port_ccmgta_attributes,
298+
.bin_attrs_new = port_ccmgta_attributes,
299299
};
300300

301301
/* Start sl2vl */

0 commit comments

Comments
 (0)