[PATCH] regulator: da9063: kzalloc + kcalloc to kzalloc

Rosen Penev posted 1 patch 4 weeks ago
drivers/regulator/da9063-regulator.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
[PATCH] regulator: da9063: kzalloc + kcalloc to kzalloc
Posted by Rosen Penev 4 weeks ago
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>
---
 drivers/regulator/da9063-regulator.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c
index 9d369cc45d41..bf34ea440d77 100644
--- a/drivers/regulator/da9063-regulator.c
+++ b/drivers/regulator/da9063-regulator.c
@@ -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;
-- 
2.53.0
Re: [PATCH] regulator: da9063: kzalloc + kcalloc to kzalloc
Posted by Mark Brown 3 weeks, 3 days ago
On Tue, 10 Mar 2026 17:41:59 -0700, Rosen Penev wrote:
> regulator: da9063: kzalloc + kcalloc to kzalloc

Applied to

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

Thanks!

[1/1] regulator: da9063: kzalloc + kcalloc to kzalloc
      https://git.kernel.org/broonie/misc/c/cf4812898b58

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