ASoC: Add a sanity check before using dai driver name
PATCH 1/1 ASoC: Add a sanity check before using dai driver name
The dai driver's name is allowed to be NULL. So add a sanity check for that.
---
sound/soc/soc-core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
sound/soc/soc-core.c +7 -5
@@ -978,11 +978,13 @@ struct snd_soc_dai *snd_soc_find_dai(if (dlc->name &&strcmp (component->name, dlc->name))continue ;list_for_each_entry (dai, &component->dai_list, list) { -if (dlc->dai_name &&strcmp (dai->name, dlc->dai_name) - &&strcmp (dai->driver->name, dlc->dai_name)) -continue ; - -return dai; +if (!dlc->dai_name) +return dai; +if (!strcmp (dai->name, dlc->dai_name)) +return dai; +if (dai->driver->name && + !strcmp (dai->driver->name, dlc->dai_name)) +return dai; } }
Signature · 1 line
2.11.0
Mark Brown
maintainersound/soc/soc-core.c struct snd_soc_dai *snd_soc_find_dai( · line 984
Quoted 5 lines · Jeffy Chen
sound/soc/soc-core.c +4
-1-return dai; +if (!dlc->dai_name) +return dai; +if (!strcmp (dai->name, dlc->dai_name)) +return dai;
You want (dlc->dai_name && !strcmp(dai->name, dlc->dai_name)) for this to be equivalent don't you?
Quoted 2 lines
sound/soc/soc-core.c +2
-0+if (dai->driver->name && + !strcmp (dai->driver->name, dlc->dai_name))
hi Mark,
Quoted 10 lines · Mark Brown
sound/soc/soc-core.c struct snd_soc_dai *snd_soc_find_dai( · line 984
Quoted 5 lines · Jeffy Chen
sound/soc/soc-core.c +4
-1-return dai; +if (!dlc->dai_name) +return dai; +if (!strcmp (dai->name, dlc->dai_name)) +return dai;You want (
dlc->dai_name&& !strcmp(dai->name,dlc->dai_name)) for this to be equivalent don't you?
i think the original check is allowing NULL dlc dai_name to be a match... so we basically did:
reject when dlc dai_name is valid, but not match the dai name
and my patch is:
accept when dlc dai_name is invalid
accept when match dai name
accept when match dai driver name(only when it is valid)
so it's a "if (a && b) reject" to "if (!a || !b) accept" case..
Quoted 4 lines
Quoted 3 lines
sound/soc/soc-core.c +2
-0+if (dai->driver->name && + !strcmp (dai->driver->name, dlc->dai_name))
Mark Brown
maintainerQuoted 3 lines · jeffy
i think the original check is allowing NULL dlc
dai_nameto be a match... so we basically did:
reject when dlcdai_nameis valid, but not match the dai name
So it is, but this still looks like the wrong thing - it'll match on an empty DAI name over an explicit match on the driver name which seems like it's the wrong way round.
Quoted 14 lines
and my patch is:
accept when dlcdai_nameis invalid
accept when match dai name
accept when match dai driver name(only when it is valid)so it's a "if (a && b) reject" to "if (!a || !b) accept" case..
Quoted 4 lines
Quoted 3 lines
sound/soc/soc-core.c +2
-0+if (dai->driver->name && + !strcmp (dai->driver->name, dlc->dai_name))
Hi Mark,
Quoted 9 lines · Mark Brown
Quoted 3 lines · jeffy
Quoted 3 lines
i think the original check is allowing NULL dlc
dai_nameto be a match... so we basically did:
reject when dlcdai_nameis valid, but not match the dai nameSo it is, but this still looks like the wrong thing - it'll match on an empty DAI name over an explicit match on the driver name which seems like it's the wrong way round.
sorry, i don't know much about asoc, so i just trying to keep the original conditions and add the new one on it :)
the original one is:
if (dlc->dai_name && strcmp(dai->name, dlc->dai_name))
continue;
and i was trying to do something like:
if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)
&& (!dai->driver->name || strcmp(dai->driver->name, dlc->dai_name)))
continue;
which is add an accept case for: dai driver name is valid and matches the dai name we are looking for...
Mark Brown
maintainerQuoted 7 lines · jeffy
and i was trying to do something like:
if (dlc->dai_name&&strcmp(dai->name, dlc->dai_name)&& (!dai->driver->name || strcmp(dai->driver->name, dlc->dai_name)))continue;
which is add an accept case for: dai driver name is valid and matches the dai name we are looking for...
Writing it as one if statement would at least be clearer. I can't remember the patch you proposed at this point but the above looks plausible.
hi Mark,
Quoted 7 lines · Mark Brown
Quoted 4 lines · jeffy
and i was trying to do something like:
if (dlc->dai_name&&strcmp(dai->name, dlc->dai_name)&& (!dai->driver->name || strcmp(dai->driver->name, dlc->dai_name))) continue;
Quoted 6 lines
Quoted 2 lines
which is add an accept case for: dai driver name is valid and matches the dai name we are looking for...
Writing it as one if statement would at least be clearer. I can't remember the patch you proposed at this point but the above looks plausible.
right, i've already post a v3 for that ;)