Skip to contentSkip to conversation

ASoC: Add a sanity check before using dai driver name

PATCH Superseded Jeffy Chen 2 participants 7 messages Aug 22, 2017 – Aug 24, 2017

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jeffy Chen

author
#0 lore raw

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
index 77e7e2a11af0..8ab9ee2b460a 100644
@@ -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
maintainer
#1 lore raw

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?

Quoted 2 lines
sound/soc/soc-core.c +2 -0
+			if (dai->driver->name &&
+			    !strcmp(dai->driver->name, dlc->dai_name))
author
#2 lore raw

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))
maintainer
#3 lore raw
Quoted 3 lines · jeffy

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

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 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))
author
#4 lore raw

Hi Mark,

Quoted 9 lines · Mark Brown
Quoted 3 lines · jeffy
Quoted 3 lines

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

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.

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...

maintainer
#5 lore raw
Quoted 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.

author
#6 lore raw

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 ;)

Quoted 1 line