[PATCH] hwmon: (pmbus/mpq7932) Constify struct regulator_desc

Christophe JAILLET posted 1 patch 2 months, 3 weeks ago
drivers/hwmon/pmbus/mpq7932.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] hwmon: (pmbus/mpq7932) Constify struct regulator_desc
Posted by Christophe JAILLET 2 months, 3 weeks ago
'struct regulator_desc' is not modified in this driver.

Constifying this structure moves some data to a read-only section, so
increase overall security, especially when the structure holds some
function pointers.

This also makes mpq7932_regulators_desc consistent with
mpq7932_regulators_desc_one which is already a "static const struct
regulator_desc".

On a x86_64, with allmodconfig:
Before:
======
   text	   data	    bss	    dec	    hex	filename
   3516	   2264	      0	   5780	   1694	drivers/hwmon/pmbus/mpq7932.o

After:
=====
   text	   data	    bss	    dec	    hex	filename
   5396	    384	      0	   5780	   1694	drivers/hwmon/pmbus/mpq7932.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
--
Compile tested only
---
 drivers/hwmon/pmbus/mpq7932.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/mpq7932.c b/drivers/hwmon/pmbus/mpq7932.c
index 67487867c70f..2dcb6da853bd 100644
--- a/drivers/hwmon/pmbus/mpq7932.c
+++ b/drivers/hwmon/pmbus/mpq7932.c
@@ -35,7 +35,7 @@ struct mpq7932_data {
 };
 
 #if IS_ENABLED(CONFIG_SENSORS_MPQ7932_REGULATOR)
-static struct regulator_desc mpq7932_regulators_desc[] = {
+static const struct regulator_desc mpq7932_regulators_desc[] = {
 	PMBUS_REGULATOR_STEP("buck", 0, MPQ7932_N_VOLTAGES,
 			     MPQ7932_UV_STEP, MPQ7932_BUCK_UV_MIN),
 	PMBUS_REGULATOR_STEP("buck", 1, MPQ7932_N_VOLTAGES,
-- 
2.46.0
Re: [PATCH] hwmon: (pmbus/mpq7932) Constify struct regulator_desc
Posted by Guenter Roeck 2 months, 3 weeks ago
On Sun, Sep 08, 2024 at 10:32:38AM +0200, Christophe JAILLET wrote:
> 'struct regulator_desc' is not modified in this driver.
> 
> Constifying this structure moves some data to a read-only section, so
> increase overall security, especially when the structure holds some
> function pointers.
> 
> This also makes mpq7932_regulators_desc consistent with
> mpq7932_regulators_desc_one which is already a "static const struct
> regulator_desc".
> 
> On a x86_64, with allmodconfig:
> Before:
> ======
>    text	   data	    bss	    dec	    hex	filename
>    3516	   2264	      0	   5780	   1694	drivers/hwmon/pmbus/mpq7932.o
> 
> After:
> =====
>    text	   data	    bss	    dec	    hex	filename
>    5396	    384	      0	   5780	   1694	drivers/hwmon/pmbus/mpq7932.o
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---

Applied.

Thanks,
Guenter