]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ASoC: Intel: avs: Do not share the name pointer between components
authorCezary Rojewski <cezary.rojewski@intel.com>
Mon, 18 Aug 2025 10:41:25 +0000 (12:41 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Nov 2025 20:37:03 +0000 (15:37 -0500)
[ Upstream commit 4dee5c1cc439b0d5ef87f741518268ad6a95b23d ]

By sharing 'name' directly, tearing down components may lead to
use-after-free errors. Duplicate the name to avoid that.

At the same time, update the order of operations - since commit
cee28113db17 ("ASoC: dmaengine_pcm: Allow passing component name via
config") the framework does not override component->name if set before
invoking the initializer.

Reviewed-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
Link: https://patch.msgid.link/20250818104126.526442-4-cezary.rojewski@intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/soc/intel/avs/pcm.c

index 0180cf7d5fe15a53386933eb8b43784efe584bb9..306c94911a775e31db983f525ba74c230356c5f4 100644 (file)
@@ -1393,16 +1393,18 @@ int avs_soc_component_register(struct device *dev, const char *name,
        if (!acomp)
                return -ENOMEM;
 
-       ret = snd_soc_component_initialize(&acomp->base, drv, dev);
-       if (ret < 0)
-               return ret;
+       acomp->base.name = devm_kstrdup(dev, name, GFP_KERNEL);
+       if (!acomp->base.name)
+               return -ENOMEM;
 
-       /* force name change after ASoC is done with its init */
-       acomp->base.name = name;
        INIT_LIST_HEAD(&acomp->node);
 
        drv->use_dai_pcm_id = !obsolete_card_names;
 
+       ret = snd_soc_component_initialize(&acomp->base, drv, dev);
+       if (ret < 0)
+               return ret;
+
        return snd_soc_add_component(&acomp->base, cpu_dais, num_cpu_dais);
 }