* [PATCH] ata: ahci_tegra: remove kcalloc
@ 2026-03-24 21:16 Rosen Penev
2026-03-24 22:10 ` Damien Le Moal
2026-03-25 7:30 ` Niklas Cassel
0 siblings, 2 replies; 6+ messages in thread
From: Rosen Penev @ 2026-03-24 21:16 UTC (permalink / raw)
To: linux-ide
Cc: Damien Le Moal, Niklas Cassel, Thierry Reding, Jonathan Hunter,
open list:TEGRA ARCHITECTURE SUPPORT, open list
Combine allocations into one by using a flexible array member.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
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[];
};
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);
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] ata: ahci_tegra: remove kcalloc
2026-03-24 21:16 [PATCH] ata: ahci_tegra: remove kcalloc Rosen Penev
@ 2026-03-24 22:10 ` Damien Le Moal
2026-03-24 22:51 ` Rosen Penev
2026-03-25 7:30 ` Niklas Cassel
1 sibling, 1 reply; 6+ messages in thread
From: Damien Le Moal @ 2026-03-24 22:10 UTC (permalink / raw)
To: Rosen Penev, linux-ide
Cc: Niklas Cassel, Thierry Reding, Jonathan Hunter,
open list:TEGRA ARCHITECTURE SUPPORT, open list
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@gmail.com>
> ---
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ata: ahci_tegra: remove kcalloc
2026-03-24 22:10 ` Damien Le Moal
@ 2026-03-24 22:51 ` Rosen Penev
0 siblings, 0 replies; 6+ messages in thread
From: Rosen Penev @ 2026-03-24 22:51 UTC (permalink / raw)
To: Damien Le Moal
Cc: linux-ide, Niklas Cassel, Thierry Reding, Jonathan Hunter,
open list:TEGRA ARCHITECTURE SUPPORT, open list
On Tue, Mar 24, 2026 at 3:10 PM Damien Le Moal <dlemoal@kernel.org> wrote:
>
> 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@gmail.com>
> > ---
> > 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.
Is it really worth it to make a copy?
>
> > };
> >
> > 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ata: ahci_tegra: remove kcalloc
2026-03-24 21:16 [PATCH] ata: ahci_tegra: remove kcalloc Rosen Penev
2026-03-24 22:10 ` Damien Le Moal
@ 2026-03-25 7:30 ` Niklas Cassel
2026-03-25 10:17 ` Jon Hunter
1 sibling, 1 reply; 6+ messages in thread
From: Niklas Cassel @ 2026-03-25 7:30 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-ide, Damien Le Moal, Thierry Reding, Jonathan Hunter,
open list:TEGRA ARCHITECTURE SUPPORT, open list
Hello Rosen,
subject is a bit misleading:
"remove kcalloc"
you are removing devm_kcalloc(), so device managed.
On Tue, Mar 24, 2026 at 02:16:29PM -0700, Rosen Penev wrote:
> Combine allocations into one by using a flexible array member.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> 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[];
Personally I'm not a big fan of flexible array members, as there can be
only one. And if you use it you want to use counted_by().
Yes, there are two device managed allocations. But is that so bad?
Since it is device managed, it will get freed on device removal anyway.
Kind regards,
Niklas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ata: ahci_tegra: remove kcalloc
2026-03-25 7:30 ` Niklas Cassel
@ 2026-03-25 10:17 ` Jon Hunter
2026-03-25 23:29 ` Rosen Penev
0 siblings, 1 reply; 6+ messages in thread
From: Jon Hunter @ 2026-03-25 10:17 UTC (permalink / raw)
To: Niklas Cassel, Rosen Penev
Cc: linux-ide, Damien Le Moal, Thierry Reding,
open list:TEGRA ARCHITECTURE SUPPORT, open list
On 25/03/2026 07:30, Niklas Cassel wrote:
> Hello Rosen,
>
> subject is a bit misleading:
> "remove kcalloc"
> you are removing devm_kcalloc(), so device managed.
>
>
> On Tue, Mar 24, 2026 at 02:16:29PM -0700, Rosen Penev wrote:
>> Combine allocations into one by using a flexible array member.
>>
>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>> ---
>> 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[];
>
> Personally I'm not a big fan of flexible array members, as there can be
> only one. And if you use it you want to use counted_by().
>
> Yes, there are two device managed allocations. But is that so bad?
>
> Since it is device managed, it will get freed on device removal anyway.
FWIW I am not a big fan of this either. It is not an obvious bang for
the buck for me. The one downside I see is that it does leave the door
open for someone accidentally putting another variable after the
flexible array member. Yes we should catch this in review, but there
really should be at least a comment saying this must be the final member
of the struct.
Jon
--
nvpublic
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ata: ahci_tegra: remove kcalloc
2026-03-25 10:17 ` Jon Hunter
@ 2026-03-25 23:29 ` Rosen Penev
0 siblings, 0 replies; 6+ messages in thread
From: Rosen Penev @ 2026-03-25 23:29 UTC (permalink / raw)
To: Jon Hunter
Cc: Niklas Cassel, linux-ide, Damien Le Moal, Thierry Reding,
open list:TEGRA ARCHITECTURE SUPPORT, open list
On Wed, Mar 25, 2026 at 3:17 AM Jon Hunter <jonathanh@nvidia.com> wrote:
>
>
> On 25/03/2026 07:30, Niklas Cassel wrote:
> > Hello Rosen,
> >
> > subject is a bit misleading:
> > "remove kcalloc"
> > you are removing devm_kcalloc(), so device managed.
> >
> >
> > On Tue, Mar 24, 2026 at 02:16:29PM -0700, Rosen Penev wrote:
> >> Combine allocations into one by using a flexible array member.
> >>
> >> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> >> ---
> >> 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[];
> >
> > Personally I'm not a big fan of flexible array members, as there can be
> > only one. And if you use it you want to use counted_by().
> >
> > Yes, there are two device managed allocations. But is that so bad?
> >
> > Since it is device managed, it will get freed on device removal anyway.
>
> FWIW I am not a big fan of this either. It is not an obvious bang for
> the buck for me. The one downside I see is that it does leave the door
> open for someone accidentally putting another variable after the
> flexible array member. Yes we should catch this in review, but there
> really should be at least a comment saying this must be the final member
> of the struct.
That will eventually become a compile time error. Currently there are
a bunch of those cases that need to get fixed before that happens.
Hardening people are working on it.
>
> Jon
>
> --
> nvpublic
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-25 23:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-24 21:16 [PATCH] ata: ahci_tegra: remove kcalloc Rosen Penev
2026-03-24 22:10 ` Damien Le Moal
2026-03-24 22:51 ` Rosen Penev
2026-03-25 7:30 ` Niklas Cassel
2026-03-25 10:17 ` Jon Hunter
2026-03-25 23:29 ` Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox