Skip to contentSkip to conversation

staging: fieldbus: arcx-anybus: constify static structs

PATCH In review Rikard Falkeborn 2 participants 2 messages Feb 7, 2021 – Feb 8, 2021 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: fieldbus: arcx-anybus: constify static structs

Constify two static structs which are never modified, to allow the compiler to put them in read-only memory.

The only usage of controller_attribute_group is to put its address in an array of pointers to const struct attribute_group, and the only usage of can_power_ops is to assign its address to the 'ops' field in the regulator_desc struct, which is a pointer to const struct regulator_ops.

---
 drivers/staging/fieldbus/anybuss/arcx-anybus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/fieldbus/anybuss/arcx-anybus.c +2 -2
index b5fded15e8a6..9af2e63050d1 100644
@@ -185,7 +185,7 @@ static struct attribute *controller_attributes[] = {
 	NULL,
 };
 
-static struct attribute_group controller_attribute_group = {
+static const struct attribute_group controller_attribute_group = {
 	.attrs = controller_attributes,
 };
 
@@ -206,7 +206,7 @@ static int can_power_is_enabled(struct regulator_dev *rdev)
 	return !(readb(cd->cpld_base + CPLD_STATUS1) & CPLD_STATUS1_CAN_POWER);
 }
 
-static struct regulator_ops can_power_ops = {
+static const struct regulator_ops can_power_ops = {
 	.is_enabled = can_power_is_enabled,
 };
 
Signature · 1 line
2.30.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Rikard, thank you for the contribution.

Quoted 10 lines · Rikard Falkeborn

Constify two static structs which are never modified, to allow the compiler to put them in read-only memory.

The only usage of controller_attribute_group is to put its address in an array of pointers to const struct attribute_group, and the only usage of can_power_ops is to assign its address to the 'ops' field in the regulator_desc struct, which is a pointer to const struct regulator_ops.