]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ASoC: tegra: ADMAIF: allocate with a single kzalloc
authorRosen Penev <rosenp@gmail.com>
Sun, 3 May 2026 00:30:37 +0000 (17:30 -0700)
committerMark Brown <broonie@kernel.org>
Mon, 4 May 2026 13:01:48 +0000 (22:01 +0900)
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.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://patch.msgid.link/20260503003037.11942-1-rosenp@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/tegra/tegra210_admaif.c
sound/soc/tegra/tegra210_admaif.h
sound/soc/tegra/tegra_isomgr_bw.c

index a1c2757a39320c4d9e868ad97d681fc56ff83408..7299c6bfcf158117dadf1a06b9f6af765f786f48 100644 (file)
@@ -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,
index 304d45c76a9af00a00dcecffdf910ed0047eb69d..fd9877aa95d3868eafb843c3ea4b2f3d12902a99 100644 (file)
@@ -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
index fa979960bc0968313b45bc3ca311c1ecf1ff3a1c..c0f300fb3d381bde6cf191e8985c7cc8619fd6e9 100644 (file)
@@ -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"