From: Rosen Penev <rosenp@gmail.com>
To: linux-sound@vger.kernel.org
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
Thierry Reding <thierry.reding@kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
linux-tegra@vger.kernel.org (open list:TEGRA ARCHITECTURE
SUPPORT), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] ASoC: tegra: ADMAIF: allocate with a single kzalloc
Date: Thu, 30 Apr 2026 14:42:02 -0700 [thread overview]
Message-ID: <20260430214202.58405-1-rosenp@gmail.com> (raw)
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
Consolidate the allocations for capture_dma_data and playback_dma_data
into a single kzalloc by using a flexible array member at the end of
the tegra_admaif struct. This reduces the number of allocations from
three to one, simplifies error handling, and improves memory locality.
sound/soc/tegra/tegra210_admaif.c | 28 ++++++++++------------------
sound/soc/tegra/tegra210_admaif.h | 2 +-
sound/soc/tegra/tegra_isomgr_bw.c | 1 +
3 files changed, 12 insertions(+), 19 deletions(-)
diff --git a/sound/soc/tegra/tegra210_admaif.c b/sound/soc/tegra/tegra210_admaif.c
index a1c2757a3932..7299c6bfcf15 100644
--- a/sound/soc/tegra/tegra210_admaif.c
+++ b/sound/soc/tegra/tegra210_admaif.c
@@ -11,6 +11,7 @@
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/regmap.h>
+#include <sound/dmaengine_pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include "tegra_isomgr_bw.h"
@@ -912,35 +913,26 @@ MODULE_DEVICE_TABLE(of, tegra_admaif_of_match);
static int tegra_admaif_probe(struct platform_device *pdev)
{
+ const struct tegra_admaif_soc_data *soc_data;
struct tegra_admaif *admaif;
void __iomem *regs;
struct resource *res;
+ size_t alloc_size;
int err, i;
- admaif = devm_kzalloc(&pdev->dev, sizeof(*admaif), GFP_KERNEL);
+ soc_data = of_device_get_match_data(&pdev->dev);
+
+ alloc_size = struct_size(admaif, capture_dma_data, soc_data->num_ch);
+ alloc_size += sizeof(*admaif->playback_dma_data) * soc_data->num_ch;
+ admaif = devm_kzalloc(&pdev->dev, alloc_size, GFP_KERNEL);
if (!admaif)
return -ENOMEM;
- admaif->soc_data = of_device_get_match_data(&pdev->dev);
+ admaif->playback_dma_data = admaif->capture_dma_data + soc_data->num_ch;
+ admaif->soc_data = soc_data;
dev_set_drvdata(&pdev->dev, admaif);
- admaif->capture_dma_data =
- devm_kcalloc(&pdev->dev,
- admaif->soc_data->num_ch,
- sizeof(struct snd_dmaengine_dai_dma_data),
- GFP_KERNEL);
- if (!admaif->capture_dma_data)
- return -ENOMEM;
-
- admaif->playback_dma_data =
- devm_kcalloc(&pdev->dev,
- admaif->soc_data->num_ch,
- sizeof(struct snd_dmaengine_dai_dma_data),
- GFP_KERNEL);
- if (!admaif->playback_dma_data)
- return -ENOMEM;
-
for (i = 0; i < ADMAIF_PATHS; i++) {
admaif->mono_to_stereo[i] =
devm_kcalloc(&pdev->dev, admaif->soc_data->num_ch,
diff --git a/sound/soc/tegra/tegra210_admaif.h b/sound/soc/tegra/tegra210_admaif.h
index 304d45c76a9a..fd9877aa95d3 100644
--- a/sound/soc/tegra/tegra210_admaif.h
+++ b/sound/soc/tegra/tegra210_admaif.h
@@ -229,13 +229,13 @@ struct tegra_admaif_soc_data {
};
struct tegra_admaif {
- struct snd_dmaengine_dai_dma_data *capture_dma_data;
struct snd_dmaengine_dai_dma_data *playback_dma_data;
const struct tegra_admaif_soc_data *soc_data;
unsigned int *mono_to_stereo[ADMAIF_PATHS];
unsigned int *stereo_to_mono[ADMAIF_PATHS];
struct regmap *regmap;
struct tegra_adma_isomgr *adma_isomgr;
+ struct snd_dmaengine_dai_dma_data capture_dma_data[];
};
#endif
diff --git a/sound/soc/tegra/tegra_isomgr_bw.c b/sound/soc/tegra/tegra_isomgr_bw.c
index fa979960bc09..c0f300fb3d38 100644
--- a/sound/soc/tegra/tegra_isomgr_bw.c
+++ b/sound/soc/tegra/tegra_isomgr_bw.c
@@ -6,6 +6,7 @@
#include <linux/interconnect.h>
#include <linux/module.h>
+#include <sound/dmaengine_pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include "tegra_isomgr_bw.h"
--
2.54.0
next reply other threads:[~2026-04-30 21:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 21:42 Rosen Penev [this message]
2026-05-01 0:57 ` [PATCH] ASoC: tegra: ADMAIF: allocate with a single kzalloc Mark Brown
2026-05-01 1:14 ` Rosen Penev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260430214202.58405-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=broonie@kernel.org \
--cc=jonathanh@nvidia.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=perex@perex.cz \
--cc=thierry.reding@kernel.org \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox