RDMA: Constify static struct attribute_group
Subsystems (2)
cover RDMA: Constify static struct attribute_group
Constify a couple of static struct attribute_group that are never modified to allow the compiler to put them in read-only memory.
Rikard Falkeborn (2):
RDMA/core: Constify struct attribute_group RDMA/rtrs: Constify static struct attribute_group
drivers/infiniband/core/sysfs.c | 12 ++++++------ drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c | 6 +++--- drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-)
Signature · 1 line
2.28.0
PATCH 1/2 RDMA/core: Constify struct attribute_group
The only usage of the pma_table field in the ib_port struct is to pass its address to sysfs_create_group() and sysfs_remove_group(). Make it const to make it possible to constify a couple of static struct attribute_group. This allows the compiler to put them in read-only memory.
--- drivers/infiniband/core/sysfs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/infiniband/core/sysfs.c +6 -6
@@ -59,7 +59,7 @@ struct ib_port {struct gid_attr_group *gid_attr_group;struct attribute_group gid_group;struct attribute_group *pkey_group; -struct attribute_group *pma_table; +const struct attribute_group *pma_table;struct attribute_group *hw_stats_ag;struct rdma_hw_stats *hw_stats;u8 port_num;
@@ -653,17 +653,17 @@ static struct attribute *pma_attrs_noietf[] = { NULL }; -static struct attribute_group pma_group = { +static const struct attribute_group pma_group = { .name ="counters" , .attrs = pma_attrs }; -static struct attribute_group pma_group_ext = { +static const struct attribute_group pma_group_ext = { .name ="counters" , .attrs = pma_attrs_ext }; -static struct attribute_group pma_group_noietf = { +static const struct attribute_group pma_group_noietf = { .name ="counters" , .attrs = pma_attrs_noietf };
@@ -778,8 +778,8 @@ alloc_group_attrs(ssize_t (*show)(struct ib_port *,* Figure out which counter table to use depending on * the device capabilities. */ -static struct attribute_group *get_counter_table (struct ib_device *dev, -int port_num) +static const struct attribute_group *get_counter_table (struct ib_device *dev, +int port_num) {struct ib_class_port_info cpi;
Signature · 1 line
2.28.0
PATCH 2/2 RDMA/rtrs: Constify static struct attribute_group
In reply to Rikard FalkebornThe only usage of these is to pass their address to sysfs_create_group() and sysfs_remove_group(), both which takes const pointers. Make the const to allow the compiler to put them in read-only memory.
--- drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c | 6 +++--- drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c +3 -3
@@ -312,7 +312,7 @@ static struct attribute *rtrs_clt_stats_attrs[] = { NULL }; -static struct attribute_group rtrs_clt_stats_attr_group = { +static const struct attribute_group rtrs_clt_stats_attr_group = { .attrs = rtrs_clt_stats_attrs, };
@@ -388,7 +388,7 @@ static struct attribute *rtrs_clt_sess_attrs[] = { NULL, }; -static struct attribute_group rtrs_clt_sess_attr_group = { +static const struct attribute_group rtrs_clt_sess_attr_group = { .attrs = rtrs_clt_sess_attrs, };
@@ -460,7 +460,7 @@ static struct attribute *rtrs_clt_attrs[] = { NULL, }; -static struct attribute_group rtrs_clt_attr_group = { +static const struct attribute_group rtrs_clt_attr_group = { .attrs = rtrs_clt_attrs, };
drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c +2 -2
@@ -135,7 +135,7 @@ static struct attribute *rtrs_srv_sess_attrs[] = { NULL, }; -static struct attribute_group rtrs_srv_sess_attr_group = { +static const struct attribute_group rtrs_srv_sess_attr_group = { .attrs = rtrs_srv_sess_attrs, };
@@ -148,7 +148,7 @@ static struct attribute *rtrs_srv_stats_attrs[] = { NULL, }; -static struct attribute_group rtrs_srv_stats_attr_group = { +static const struct attribute_group rtrs_srv_stats_attr_group = { .attrs = rtrs_srv_stats_attrs, };
Signature · 1 line
2.28.0
Quoted 6 lines · Rikard Falkeborn
Constify a couple of static struct
attribute_groupthat are never modified to allow the compiler to put them in read-only memory.Rikard Falkeborn (2):
RDMA/core: Constify structattribute_groupRDMA/rtrs: Constify static structattribute_group
Applied to for-next, thanks
Jason