Re: [PATCH] ata: ahci_tegra: remove kcalloc
From: Damien Le Moal
Date: Tue Mar 24 2026 - 18:13:33 EST
On 2026/03/24 14:16, Rosen Penev wrote:
> Combine allocations into one by using a flexible array member.
>
> Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
> ---
> drivers/ata/ahci_tegra.c | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/ata/ahci_tegra.c b/drivers/ata/ahci_tegra.c
> index 44584eed6374..5972fe04ff3f 100644
> --- a/drivers/ata/ahci_tegra.c
> +++ b/drivers/ata/ahci_tegra.c
> @@ -175,8 +175,9 @@ struct tegra_ahci_priv {
> struct reset_control *sata_cold_rst;
> /* Needs special handling, cannot use ahci_platform */
> struct clk *sata_clk;
> - struct regulator_bulk_data *supplies;
> const struct tegra_ahci_soc *soc;
> +
> + struct regulator_bulk_data supplies[];
I think this needs a __counted_by() annotation, but not sure if that is possible
given that soc->num_supplies is not in this structure. Might need a copy of it.
> };
>
> static void tegra_ahci_handle_quirks(struct ahci_host_priv *hpriv)
> @@ -512,6 +513,7 @@ static const struct scsi_host_template ahci_platform_sht = {
>
> static int tegra_ahci_probe(struct platform_device *pdev)
> {
> + const struct tegra_ahci_soc *soc;
> struct ahci_host_priv *hpriv;
> struct tegra_ahci_priv *tegra;
> struct resource *res;
> @@ -521,14 +523,15 @@ static int tegra_ahci_probe(struct platform_device *pdev)
> if (IS_ERR(hpriv))
> return PTR_ERR(hpriv);
>
> - tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL);
> + soc = of_device_get_match_data(&pdev->dev);
> + tegra = devm_kzalloc(&pdev->dev, struct_size(tegra, supplies, soc->num_supplies), GFP_KERNEL);
> if (!tegra)
> return -ENOMEM;
>
> hpriv->plat_data = tegra;
>
> tegra->pdev = pdev;
> - tegra->soc = of_device_get_match_data(&pdev->dev);
> + tegra->soc = soc;
>
> tegra->sata_regs = devm_platform_ioremap_resource(pdev, 1);
> if (IS_ERR(tegra->sata_regs))
> @@ -571,12 +574,6 @@ static int tegra_ahci_probe(struct platform_device *pdev)
> return PTR_ERR(tegra->sata_clk);
> }
>
> - tegra->supplies = devm_kcalloc(&pdev->dev,
> - tegra->soc->num_supplies,
> - sizeof(*tegra->supplies), GFP_KERNEL);
> - if (!tegra->supplies)
> - return -ENOMEM;
> -
> regulator_bulk_set_supply_names(tegra->supplies,
> tegra->soc->supply_names,
> tegra->soc->num_supplies);
--
Damien Le Moal
Western Digital Research