public inbox for linux-tegra@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: tegra: ADX: simplify probe allocation
@ 2026-04-25  1:42 Rosen Penev
  2026-04-25  8:31 ` Jon Hunter
  0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-04-25  1:42 UTC (permalink / raw)
  To: linux-sound
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Thierry Reding, Jonathan Hunter,
	open list:TEGRA ARCHITECTURE SUPPORT, open list

Reduce 3 allocations to one using a flexible array member.

Also use of_device_get_match_data. No error checking since it cannot be
NULL.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 sound/soc/tegra/tegra210_adx.c | 24 ++++++++----------------
 sound/soc/tegra/tegra210_adx.h |  2 +-
 2 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/sound/soc/tegra/tegra210_adx.c b/sound/soc/tegra/tegra210_adx.c
index d2f742ffc59d..3f6c068d00c8 100644
--- a/sound/soc/tegra/tegra210_adx.c
+++ b/sound/soc/tegra/tegra210_adx.c
@@ -676,17 +676,20 @@ static int tegra210_adx_platform_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct tegra210_adx *adx;
-	const struct of_device_id *match;
-	struct tegra210_adx_soc_data *soc_data;
+	const struct tegra210_adx_soc_data *soc_data;
 	void __iomem *regs;
+	size_t alloc_size;
 	int err;
 
-	adx = devm_kzalloc(dev, sizeof(*adx), GFP_KERNEL);
+	soc_data = of_device_get_match_data(&pdev->dev);
+	alloc_size = struct_size(adx, map, soc_data->ram_depth);
+	alloc_size += sizeof(u32) * soc_data->byte_mask_size;
+
+	adx = devm_kzalloc(dev, alloc_size, GFP_KERNEL);
 	if (!adx)
 		return -ENOMEM;
 
-	match = of_match_device(tegra210_adx_of_match, dev);
-	soc_data = (struct tegra210_adx_soc_data *)match->data;
+	adx->byte_mask = adx->map + soc_data->ram_depth;
 	adx->soc_data = soc_data;
 
 	dev_set_drvdata(dev, adx);
@@ -703,17 +706,6 @@ static int tegra210_adx_platform_probe(struct platform_device *pdev)
 
 	regcache_cache_only(adx->regmap, true);
 
-	adx->map = devm_kzalloc(dev, soc_data->ram_depth * sizeof(*adx->map),
-				GFP_KERNEL);
-	if (!adx->map)
-		return -ENOMEM;
-
-	adx->byte_mask = devm_kzalloc(dev,
-				      soc_data->byte_mask_size * sizeof(*adx->byte_mask),
-				      GFP_KERNEL);
-	if (!adx->byte_mask)
-		return -ENOMEM;
-
 	tegra210_adx_dais[TEGRA_ADX_IN_DAI_ID].playback.channels_max =
 			adx->soc_data->max_ch;
 
diff --git a/sound/soc/tegra/tegra210_adx.h b/sound/soc/tegra/tegra210_adx.h
index 176a4e40de0a..4406a4a74496 100644
--- a/sound/soc/tegra/tegra210_adx.h
+++ b/sound/soc/tegra/tegra210_adx.h
@@ -88,9 +88,9 @@ struct tegra210_adx_soc_data {
 
 struct tegra210_adx {
 	struct regmap *regmap;
-	unsigned int *map;
 	unsigned int *byte_mask;
 	const struct tegra210_adx_soc_data *soc_data;
+	unsigned int map[];
 };
 
 #endif
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-25  8:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-25  1:42 [PATCH] ASoC: tegra: ADX: simplify probe allocation Rosen Penev
2026-04-25  8:31 ` Jon Hunter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox