[alsa-devel] [PATCH] 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.
Signed-off-by: Jeffy Chen jeffy.chen@rock-chips.com Reported-by: Donglin Peng dolinux.peng@gmail.com ---
sound/soc/soc-core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 77e7e2a11af0..8ab9ee2b460a 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -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; } }
hi Mark,
On 08/23/2017 12:17 AM, Mark Brown wrote:
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..
Hi Mark,
On 08/23/2017 07:06 PM, Mark Brown wrote:
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...
On Thu, Aug 24, 2017 at 11:29:42AM +0800, jeffy wrote:
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.
participants (3)
-
jeffy
-
Jeffy Chen
-
Mark Brown