]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: sdw_utils: Check speaker component string allocation
authorCássio Gabriel <cassiogabrielcontato@gmail.com>
Tue, 12 May 2026 14:03:53 +0000 (11:03 -0300)
committerMark Brown <broonie@kernel.org>
Thu, 14 May 2026 00:49:31 +0000 (09:49 +0900)
devm_kasprintf() can fail while building the temporary speaker
component string. If that happens, spk_components is set to NULL, but
the current code can still pass it to strlen() on a later loop iteration
or after the loop when appending the speaker component list to
card->components.

Use NULL to represent the initial "no speaker components" state, and
return -ENOMEM immediately if building spk_components fails.

Fixes: 0f60ecffbfe3 ("ASoC: sdw_utils: generate combined spk components string")
Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>
Link: https://patch.msgid.link/20260512-asoc-sdw-utils-spk-components-alloc-v1-1-c9bbd6d2e123@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sdw_utils/soc_sdw_utils.c

index be45a2e62d3ea6f613823ddf763fd573094c9f19..e440c23271001ce7564883399146bd820f47e790 100644 (file)
@@ -1114,7 +1114,7 @@ int asoc_sdw_rtd_init(struct snd_soc_pcm_runtime *rtd)
        struct asoc_sdw_codec_info *codec_info;
        struct snd_soc_dai *dai;
        struct sdw_slave *sdw_peripheral;
-       const char *spk_components="";
+       const char *spk_components = NULL;
        int dai_index;
        int ret;
        int i;
@@ -1197,7 +1197,7 @@ skip_add_controls_widgets:
                        else
                                component = codec_info->dais[dai_index].component_name;
 
-                       if (strlen (spk_components) == 0)
+                       if (!spk_components)
                                spk_components =
                                        devm_kasprintf(card->dev, GFP_KERNEL, "%s", component);
                        else
@@ -1205,13 +1205,15 @@ skip_add_controls_widgets:
                                spk_components =
                                        devm_kasprintf(card->dev, GFP_KERNEL,
                                                       "%s+%s", spk_components, component);
+
+                       if (!spk_components)
+                               return -ENOMEM;
                }
 
                codec_info->dais[dai_index].rtd_init_done = true;
-
        }
 
-       if (strlen (spk_components) > 0) {
+       if (spk_components) {
                /* Update card components for speaker components */
                card->components = devm_kasprintf(card->dev, GFP_KERNEL, "%s spk:%s",
                                                  card->components, spk_components);