From: Rosen Penev Date: Wed, 11 Mar 2026 00:41:59 +0000 (-0700) Subject: regulator: da9063: kzalloc + kcalloc to kzalloc X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf4812898b58228d9705a9426e8351360b25c5a4;p=thirdparty%2Flinux.git regulator: da9063: kzalloc + kcalloc to kzalloc 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 Link: https://patch.msgid.link/20260311004159.32374-1-rosenp@gmail.com Signed-off-by: Mark Brown --- diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c index 9d369cc45d417..bf34ea440d77c 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;