]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
regulator: da9063: kzalloc + kcalloc to kzalloc
authorRosen Penev <rosenp@gmail.com>
Wed, 11 Mar 2026 00:41:59 +0000 (17:41 -0700)
committerMark Brown <broonie@kernel.org>
Thu, 12 Mar 2026 23:16:17 +0000 (23:16 +0000)
Reduce main allocation to a single kzalloc call by using a flexible
array member.

Allows using __counted_by for extra runtime analysis.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://patch.msgid.link/20260311004159.32374-1-rosenp@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/da9063-regulator.c

index 9d369cc45d4178f93e0efd6a0d298ed64a62609c..bf34ea440d77c0318dcc143a4bc52687d9b109c2 100644 (file)
@@ -67,7 +67,7 @@ struct da9063_regulator_data {
 
 struct da9063_regulators_pdata {
        unsigned int                    n_regulators;
-       struct da9063_regulator_data    *regulator_data;
+       struct da9063_regulator_data    regulator_data[] __counted_by(n_regulators);
 };
 
 /* Regulator capabilities and registers description */
@@ -857,15 +857,10 @@ static struct da9063_regulators_pdata *da9063_parse_regulators_dt(
                return ERR_PTR(-EINVAL);
        }
 
-       pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+       pdata = devm_kzalloc(&pdev->dev, struct_size(pdata, regulator_data, num), GFP_KERNEL);
        if (!pdata)
                return ERR_PTR(-ENOMEM);
 
-       pdata->regulator_data = devm_kcalloc(&pdev->dev,
-                                       num, sizeof(*pdata->regulator_data),
-                                       GFP_KERNEL);
-       if (!pdata->regulator_data)
-               return ERR_PTR(-ENOMEM);
        pdata->n_regulators = num;
 
        n = 0;