Re: [PATCH] ata: ahci_tegra: remove kcalloc

From: Jon Hunter

Date: Wed Mar 25 2026 - 06:26:46 EST



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@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[];

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