Skip to content

Commit 628479a

Browse files
wensbroonie
authored andcommitted
ASoC: soc-utils: Check string pointer validity in snd_soc_dlc_is_dummy()
In the recently added snd_soc_dlc_is_dummy(), the helper uses the .name and .dai_name fields without checking their validity. For .name, this field is NULL if the component is matched by .of_node instead. In fact, only one of these fields may be set. This caused a NULL pointer dereference on MediaTek MT8195 and MT8188 platforms with the subsequent conversion to snd_soc_dlc_is_dummy() in their machine drivers. The codecs are all matches through the device tree, so their .name fields are empty. For .dai_name, there are cases where this field is empty, such as for the following component definitions: #define COMP_EMPTY() { } #define COMP_PLATFORM(_name) { .name = _name } #define COMP_AUX(_name) { .name = _name } #define COMP_CODEC_CONF(_name) { .name = _name } Or the single link CPU DAI case in the simple audio card family, as covered by simple_util_canonicalize_cpu(), in which the .dai_name field is explicitly cleared. To fix this, check the validity of the fields before using them in string comparison. Fixes: 3e021f3 ("ASoC: soc-utils: add snd_soc_dlc_is_dummy()") Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://patch.msgid.link/20250516050549.407133-1-wenst@chromium.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent a9fa131 commit 628479a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sound/soc/soc-utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ int snd_soc_dlc_is_dummy(struct snd_soc_dai_link_component *dlc)
267267
if (dlc == &snd_soc_dummy_dlc)
268268
return true;
269269

270-
if (strcmp(dlc->name, snd_soc_dummy_dlc.name) == 0 ||
271-
strcmp(dlc->dai_name, snd_soc_dummy_dlc.dai_name) == 0)
270+
if ((dlc->name && strcmp(dlc->name, snd_soc_dummy_dlc.name) == 0) ||
271+
(dlc->dai_name && strcmp(dlc->dai_name, snd_soc_dummy_dlc.dai_name) == 0))
272272
return true;
273273

274274
return false;

0 commit comments

Comments
 (0)