Skip to contentSkip to conversation

RDMA: Constify static struct attribute_group

PATCH Applied Rikard Falkeborn 2 participants 4 messages Sep 30, 2020 – Oct 1, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index c11e50510e49..453d1c451ed5 100644
@@ -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
#2 lore raw

PATCH 2/2 RDMA/rtrs: Constify static struct attribute_group

In reply to Rikard Falkeborn

The 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
index 298b747d0330..ac4c49cbf153 100644
@@ -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
index cf6a2be61695..07fbb063555d 100644
@@ -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
maintainer Applied
#3 lore raw
In reply to Rikard Falkeborn
Quoted 6 lines · Rikard Falkeborn

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

Applied to for-next, thanks

Jason