Re: [PATCH] regulator: 88pm886: Constify struct regulator_desc

From: Karel Balej
Date: Mon Sep 09 2024 - 06:45:41 EST


Christophe JAILLET, 2024-09-08T10:25:56+02:00:
> '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

"increases"?

> function pointers.
>
> On a x86_64, with allmodconfig:
> Before:
> ======
> text data bss dec hex filename
> 3251 6928 16 10195 27d3 drivers/regulator/88pm886-regulator.o
>
> After:
> =====
> text data bss dec hex filename
> 9795 360 16 10171 27bb drivers/regulator/88pm886-regulator.o
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
> --
> Compile tested only
> ---
> drivers/regulator/88pm886-regulator.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/regulator/88pm886-regulator.c b/drivers/regulator/88pm886-regulator.c
> index a38bd4f312b7..68c83a4ebda8 100644
> --- a/drivers/regulator/88pm886-regulator.c
> +++ b/drivers/regulator/88pm886-regulator.c
> @@ -56,7 +56,7 @@ static const struct linear_range pm886_buck_volt_ranges2[] = {
> REGULATOR_LINEAR_RANGE(1600000, 80, 114, 50000),
> };
>
> -static struct regulator_desc pm886_regulators[] = {
> +static const struct regulator_desc pm886_regulators[] = {
> {
> .name = "LDO1",
> .regulators_node = "regulators",
> @@ -340,9 +340,9 @@ static struct regulator_desc pm886_regulators[] = {
> static int pm886_regulator_probe(struct platform_device *pdev)
> {
> struct pm886_chip *chip = dev_get_drvdata(pdev->dev.parent);
> + const struct regulator_desc *rdesc;
> struct regulator_config rcfg = { };
> struct device *dev = &pdev->dev;
> - struct regulator_desc *rdesc;
> struct regulator_dev *rdev;
> struct i2c_client *page;
> struct regmap *regmap;
> --
> 2.46.0

Reviewed-by: Karel Balej <balejk@xxxxxxxxx>

Thanks,
K. B.