Skip to content

Commit 39d772f

Browse files
t-8chrleon
authored andcommitted
RDMA/hfi1: 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-1-397aaa94d453@weissschuh.net Signed-off-by: Leon Romanovsky <[email protected]>
1 parent edc4ef0 commit 39d772f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/infiniband/hw/hfi1/sysfs.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ static struct hfi1_pportdata *hfi1_get_pportdata_kobj(struct kobject *kobj)
2727
* Congestion control table size followed by table entries
2828
*/
2929
static ssize_t cc_table_bin_read(struct file *filp, struct kobject *kobj,
30-
struct bin_attribute *bin_attr, char *buf,
31-
loff_t pos, size_t count)
30+
const struct bin_attribute *bin_attr,
31+
char *buf, loff_t pos, size_t count)
3232
{
3333
int ret;
3434
struct hfi1_pportdata *ppd = hfi1_get_pportdata_kobj(kobj);
@@ -57,15 +57,15 @@ static ssize_t cc_table_bin_read(struct file *filp, struct kobject *kobj,
5757

5858
return count;
5959
}
60-
static BIN_ATTR_RO(cc_table_bin, PAGE_SIZE);
60+
static const BIN_ATTR_RO(cc_table_bin, PAGE_SIZE);
6161

6262
/*
6363
* Congestion settings: port control, control map and an array of 16
6464
* entries for the congestion entries - increase, timer, event log
6565
* trigger threshold and the minimum injection rate delay.
6666
*/
6767
static ssize_t cc_setting_bin_read(struct file *filp, struct kobject *kobj,
68-
struct bin_attribute *bin_attr,
68+
const struct bin_attribute *bin_attr,
6969
char *buf, loff_t pos, size_t count)
7070
{
7171
struct hfi1_pportdata *ppd = hfi1_get_pportdata_kobj(kobj);
@@ -93,9 +93,9 @@ static ssize_t cc_setting_bin_read(struct file *filp, struct kobject *kobj,
9393

9494
return count;
9595
}
96-
static BIN_ATTR_RO(cc_setting_bin, PAGE_SIZE);
96+
static const BIN_ATTR_RO(cc_setting_bin, PAGE_SIZE);
9797

98-
static struct bin_attribute *port_cc_bin_attributes[] = {
98+
static const struct bin_attribute *const port_cc_bin_attributes[] = {
9999
&bin_attr_cc_setting_bin,
100100
&bin_attr_cc_table_bin,
101101
NULL
@@ -134,7 +134,7 @@ static struct attribute *port_cc_attributes[] = {
134134
static const struct attribute_group port_cc_group = {
135135
.name = "CCMgtA",
136136
.attrs = port_cc_attributes,
137-
.bin_attrs = port_cc_bin_attributes,
137+
.bin_attrs_new = port_cc_bin_attributes,
138138
};
139139

140140
/* Start sc2vl */

0 commit comments

Comments
 (0)