Skip to contentSkip to conversation

regulator: Constify some static struct variables

PATCH In review Rikard Falkeborn 2 participants 7 messages Jun 17, 2020 – Jun 18, 2020 Voltage and current regulator framework

lore
Share & tools
lore
#0 lore raw

cover regulator: Constify some static struct variables

Constify some static struct variables to allow the compiler to put them in read-only memory. There are more of these, but I figured I could start small. Also, is one patch per driver a good resolution or too fine-grained?

Rikard Falkeborn (5):
regulator: anatop: Constify anatop_core_rops
regulator: cpcap: Constify cpcap_regulator_ops
regulator: ltc3676: Constify ltc3676_regulators
regulator: max8907: Constify static structs
regulator: max8997: Constify struct regulator_ops

 drivers/regulator/anatop-regulator.c  |  2 +-
 drivers/regulator/cpcap-regulator.c   |  2 +-
 drivers/regulator/ltc3676.c           |  2 +-
 drivers/regulator/max8907-regulator.c |  6 +++---
 drivers/regulator/max8997-regulator.c | 14 +++++++-------
 5 files changed, 13 insertions(+), 13 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/5 regulator: anatop: Constify anatop_core_rops

anatop_core_rops is not modified and can therefore be made const which allows the compiler to put it in read-only memory.

Before:
text data bss dec hex filename
4502 412 0 4914 1332 drivers/regulator/anatop-regulator.o

After:
text data bss dec hex filename
4634 280 0 4914 1332 drivers/regulator/anatop-regulator.o

---
 drivers/regulator/anatop-regulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/anatop-regulator.c +1 -1
index ca92b3de0e9c..f9856d4e295f 100644
@@ -139,7 +139,7 @@ static struct regulator_ops anatop_rops = {
 	.map_voltage = regulator_map_voltage_linear,
 };
 
-static struct regulator_ops anatop_core_rops = {
+static const struct regulator_ops anatop_core_rops = {
 	.enable = anatop_regmap_enable,
 	.disable = anatop_regmap_disable,
 	.is_enabled = anatop_regmap_is_enabled,
Signature · 1 line
2.27.0
#2 lore raw

PATCH 2/5 regulator: cpcap: Constify cpcap_regulator_ops

In reply to Rikard Falkeborn

cpcap_regulator_ops is not modified and can be made const to allow the compiler to put it in read-only memory.

Before:
text data bss dec hex filename
14472 236 0 14708 3974 drivers/regulator/cpcap-regulator.o

After:
text data bss dec hex filename
14604 104 0 14708 3974 drivers/regulator/cpcap-regulator.o

---
 drivers/regulator/cpcap-regulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/cpcap-regulator.c +1 -1
index f80781d58a28..14642603e755 100644
@@ -256,7 +256,7 @@ static int cpcap_regulator_set_mode(struct regulator_dev *rdev,
 				  CPCAP_BIT_AUDIO_LOW_PWR, value);
 }
 
-static struct regulator_ops cpcap_regulator_ops = {
+static const struct regulator_ops cpcap_regulator_ops = {
 	.enable = cpcap_regulator_enable,
 	.disable = cpcap_regulator_disable,
 	.is_enabled = regulator_is_enabled_regmap,
Signature · 1 line
2.27.0
#3 lore raw

PATCH 3/5 regulator: ltc3676: Constify ltc3676_regulators

In reply to Rikard Falkeborn

ltc3676_regulators is not modified and can be made const to allow the compiler to put it in read-only memory.

Before:
text data bss dec hex filename
4361 2064 8 6433 1921 drivers/regulator/ltc3676.o

After:
text data bss dec hex filename
6121 304 8 6433 1921 drivers/regulator/ltc3676.o

---
 drivers/regulator/ltc3676.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/ltc3676.c +1 -1
index e12e52c69e52..093b3e4a6303 100644
@@ -221,7 +221,7 @@ static const struct regulator_ops ltc3676_fixed_regulator_ops = {
 #define LTC3676_FIXED_REG(_id, _name, _en_reg, _en_bit)                \
 	LTC3676_REG(_id, _name, fixed, LTC3676_ ## _en_reg, _en_bit, 0, 0)
 
-static struct regulator_desc ltc3676_regulators[LTC3676_NUM_REGULATORS] = {
+static const struct regulator_desc ltc3676_regulators[LTC3676_NUM_REGULATORS] = {
 	LTC3676_LINEAR_REG(SW1, sw1, BUCK1, DVB1A),
 	LTC3676_LINEAR_REG(SW2, sw2, BUCK2, DVB2A),
 	LTC3676_LINEAR_REG(SW3, sw3, BUCK3, DVB3A),
Signature · 1 line
2.27.0
#4 lore raw

PATCH 4/5 regulator: max8907: Constify static structs

In reply to Rikard Falkeborn

These are not modified so make them const to allow the compiler to put them in read-only memory.

Before:
text data bss dec hex filename
2753 7328 0 10081 2761 drivers/regulator/max8907-regulator.o

After:
text data bss dec hex filename
9405 684 0 10089 2769 drivers/regulator/max8907-regulator.o

---
 drivers/regulator/max8907-regulator.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/regulator/max8907-regulator.c +3 -3
index 96dc0eea7659..1a6fd68f3fb1 100644
@@ -109,7 +109,7 @@ struct max8907_regulator {
 static const struct regulator_ops max8907_mbatt_ops = {
 };
 
-static struct regulator_ops max8907_ldo_ops = {
+static const struct regulator_ops max8907_ldo_ops = {
 	.list_voltage = regulator_list_voltage_linear,
 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
@@ -128,7 +128,7 @@ static const struct regulator_ops max8907_fixed_ops = {
 	.list_voltage = regulator_list_voltage_linear,
 };
 
-static struct regulator_ops max8907_out5v_ops = {
+static const struct regulator_ops max8907_out5v_ops = {
 	.list_voltage = regulator_list_voltage_linear,
 	.enable = regulator_enable_regmap,
 	.disable = regulator_disable_regmap,
@@ -145,7 +145,7 @@ static const struct regulator_ops max8907_bbat_ops = {
 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 };
 
-static struct regulator_desc max8907_regulators[] = {
+static const struct regulator_desc max8907_regulators[] = {
 	REG_MBATT(),
 	REG_LDO(SD1, "in-v1", MAX8907_REG_SDCTL1, 650000, 2225000, 25000),
 	REG_LDO(SD2, "in-v2", MAX8907_REG_SDCTL2, 637500, 1425000, 12500),
Signature · 1 line
2.27.0
#5 lore raw

PATCH 5/5 regulator: max8997: Constify struct regulator_ops

In reply to Rikard Falkeborn

These are not modified so make them const to allow the compiler to put them in read-only memory.

Before:
text data bss dec hex filename
13114 8596 0 21710 54ce drivers/regulator/max8997-regulator.o

After:
text data bss dec hex filename
14038 7672 0 21710 54ce drivers/regulator/max8997-regulator.o

---
 drivers/regulator/max8997-regulator.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/regulator/max8997-regulator.c +7 -7
index 4d2487279a0a..ba47a5e2fbcb 100644
@@ -732,7 +732,7 @@ static int max8997_reg_disable_suspend(struct regulator_dev *rdev)
 	return max8997_update_reg(i2c, reg, ~pattern, mask);
 }
 
-static struct regulator_ops max8997_ldo_ops = {
+static const struct regulator_ops max8997_ldo_ops = {
 	.list_voltage		= max8997_list_voltage,
 	.is_enabled		= max8997_reg_is_enabled,
 	.enable			= max8997_reg_enable,
@@ -742,7 +742,7 @@ static struct regulator_ops max8997_ldo_ops = {
 	.set_suspend_disable	= max8997_reg_disable_suspend,
 };
 
-static struct regulator_ops max8997_buck_ops = {
+static const struct regulator_ops max8997_buck_ops = {
 	.list_voltage		= max8997_list_voltage,
 	.is_enabled		= max8997_reg_is_enabled,
 	.enable			= max8997_reg_enable,
@@ -753,7 +753,7 @@ static struct regulator_ops max8997_buck_ops = {
 	.set_suspend_disable	= max8997_reg_disable_suspend,
 };
 
-static struct regulator_ops max8997_fixedvolt_ops = {
+static const struct regulator_ops max8997_fixedvolt_ops = {
 	.list_voltage		= max8997_list_voltage,
 	.is_enabled		= max8997_reg_is_enabled,
 	.enable			= max8997_reg_enable,
@@ -761,7 +761,7 @@ static struct regulator_ops max8997_fixedvolt_ops = {
 	.set_suspend_disable	= max8997_reg_disable_suspend,
 };
 
-static struct regulator_ops max8997_safeout_ops = {
+static const struct regulator_ops max8997_safeout_ops = {
 	.list_voltage		= regulator_list_voltage_table,
 	.is_enabled		= max8997_reg_is_enabled,
 	.enable			= max8997_reg_enable,
@@ -771,7 +771,7 @@ static struct regulator_ops max8997_safeout_ops = {
 	.set_suspend_disable	= max8997_reg_disable_suspend,
 };
 
-static struct regulator_ops max8997_fixedstate_ops = {
+static const struct regulator_ops max8997_fixedstate_ops = {
 	.list_voltage		= max8997_list_voltage_charger_cv,
 	.get_voltage_sel	= max8997_get_voltage_sel,
 	.set_voltage		= max8997_set_voltage_charger_cv,
@@ -805,7 +805,7 @@ static int max8997_get_current_limit(struct regulator_dev *rdev)
 	return max8997_list_voltage(rdev, sel);
 }
 
-static struct regulator_ops max8997_charger_ops = {
+static const struct regulator_ops max8997_charger_ops = {
 	.is_enabled		= max8997_reg_is_enabled,
 	.enable			= max8997_reg_enable,
 	.disable		= max8997_reg_disable,
@@ -813,7 +813,7 @@ static struct regulator_ops max8997_charger_ops = {
 	.set_current_limit	= max8997_set_current_limit,
 };
 
-static struct regulator_ops max8997_charger_fixedstate_ops = {
+static const struct regulator_ops max8997_charger_fixedstate_ops = {
 	.get_current_limit	= max8997_get_current_limit,
 	.set_current_limit	= max8997_set_current_limit,
 };
Signature · 1 line
2.27.0
maintainer
#6 lore raw
In reply to Rikard Falkeborn
Quoted 5 lines · Rikard Falkeborn

Constify some static struct variables to allow the compiler to put them in read-only memory. There are more of these, but I figured I could start small. Also, is one patch per driver a good resolution or too fine-grained?

Quoted 8 lines

Rikard Falkeborn (5):
regulator: anatop: Constify anatop_core_rops
regulator: cpcap: Constify cpcap_regulator_ops
regulator: ltc3676: Constify ltc3676_regulators
regulator: max8907: Constify static structs
regulator: max8997: Constify struct regulator_ops

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/5] regulator: anatop: Constify anatop_core_rops

      commit: cae62a937912bd4b3faf8e268cc0ffcf00ec5850
[2/5] regulator: cpcap: Constify cpcap_regulator_ops
      commit: bcf39c1eb1e059ec612bf06f4aa7b3972dcc85e8
[3/5] regulator: ltc3676: Constify ltc3676_regulators
      commit: b37f076d4bfdd29b3aa497480b226759f659e25f
[4/5] regulator: max8907: Constify static structs
      commit: b08af72d6e5319e96527816c4b3b08d0b1a6f242
[5/5] regulator: max8997: Constify struct regulator_ops
      commit: 9ed84d24de480e81294e00814c142234bc17ce0c

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark