Skip to contentSkip to conversation

power: supply: Constify static struct attribute_group

PATCH In review Rikard Falkeborn 2 participants 4 messages Jan 13, 2021 Power supply

lore
Share & tools
lore
#0 lore raw

cover power: supply: Constify static struct attribute_group

Constify two static struct attribute_group. The only place they are used is to put their address in an array of pointers to const struct attribute_group. With these patches applied, all static attribute_group structs in drivers/power are const.

Rikard Falkeborn (2):
power: supply: ltc4162-l: Constify static struct attribute_group
power: supply: core: Constify static struct attribute_group

 drivers/power/supply/ltc4162-l-charger.c  | 2 +-
 drivers/power/supply/power_supply_sysfs.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.30.0
#1 lore raw

PATCH 1/2 power: supply: ltc4162-l: Constify static struct attribute_group

The only usage of it is to put its address in an array of pointers to const static structs. Make it const to allow the compiler to put it in read-only memory.

---
 drivers/power/supply/ltc4162-l-charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/ltc4162-l-charger.c +1 -1
index cded6484febb..1a5cb4405ee3 100644
@@ -666,7 +666,7 @@ static struct attribute *ltc4162l_sysfs_entries[] = {
 	NULL,
 };
 
-static struct attribute_group ltc4162l_attr_group = {
+static const struct attribute_group ltc4162l_attr_group = {
 	.name	= NULL,	/* put in device directory */
 	.attrs	= ltc4162l_sysfs_entries,
 };
Signature · 1 line
2.30.0
#2 lore raw

PATCH 2/2 power: supply: core: Constify static struct attribute_group

In reply to Rikard Falkeborn

The only usage of it is to put its address in an array of pointers to const static structs. Make it const to allow the compiler to put it in read-only memory.

---
 drivers/power/supply/power_supply_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/power_supply_sysfs.c +1 -1
index 92dd63171193..c3d7cbcd4fad 100644
@@ -374,7 +374,7 @@ static umode_t power_supply_attr_is_visible(struct kobject *kobj,
 	return 0;
 }
 
-static struct attribute_group power_supply_attr_group = {
+static const struct attribute_group power_supply_attr_group = {
 	.attrs = __power_supply_attrs,
 	.is_visible = power_supply_attr_is_visible,
 };
Signature · 1 line
2.30.0
#3 lore raw
In reply to Rikard Falkeborn

Hi,

Quoted 4 lines · Rikard Falkeborn

Constify two static struct attribute_group. The only place they are used is to put their address in an array of pointers to const struct attribute_group. With these patches applied, all static attribute_group structs in drivers/power are const.

Thanks, I queued both to power-supply's for-next branch.

-- Sebastian