* [PATCH] ASoC: Add a sanity check before using dai driver name
@ 2017-08-22 14:45 Jeffy Chen
2017-08-22 16:17 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: Jeffy Chen @ 2017-08-22 14:45 UTC (permalink / raw)
To: linux-kernel, broonie
Cc: tiwai, dolinux.peng, Jeffy Chen, Jaroslav Kysela, alsa-devel,
Takashi Iwai, Liam Girdwood
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;
}
}
--
2.11.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: Add a sanity check before using dai driver name
2017-08-22 14:45 [PATCH] ASoC: Add a sanity check before using dai driver name Jeffy Chen
@ 2017-08-22 16:17 ` Mark Brown
2017-08-22 23:42 ` jeffy
0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2017-08-22 16:17 UTC (permalink / raw)
To: Jeffy Chen
Cc: linux-kernel, tiwai, dolinux.peng, Jaroslav Kysela, alsa-devel,
Takashi Iwai, Liam Girdwood
[-- Attachment #1: Type: text/plain, Size: 374 bytes --]
On Tue, Aug 22, 2017 at 10:45:12PM +0800, Jeffy Chen wrote:
> - 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?
> + if (dai->driver->name &&
> + !strcmp(dai->driver->name, dlc->dai_name))
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: Add a sanity check before using dai driver name
2017-08-22 16:17 ` Mark Brown
@ 2017-08-22 23:42 ` jeffy
2017-08-23 11:06 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: jeffy @ 2017-08-22 23:42 UTC (permalink / raw)
To: Mark Brown
Cc: linux-kernel, tiwai, dolinux.peng, Jaroslav Kysela, alsa-devel,
Takashi Iwai, Liam Girdwood
hi Mark,
On 08/23/2017 12:17 AM, Mark Brown wrote:
> On Tue, Aug 22, 2017 at 10:45:12PM +0800, Jeffy Chen wrote:
>
>> - 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..
>
>> + if (dai->driver->name &&
>> + !strcmp(dai->driver->name, dlc->dai_name))
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: Add a sanity check before using dai driver name
2017-08-22 23:42 ` jeffy
@ 2017-08-23 11:06 ` Mark Brown
2017-08-24 3:29 ` jeffy
0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2017-08-23 11:06 UTC (permalink / raw)
To: jeffy
Cc: linux-kernel, tiwai, dolinux.peng, Jaroslav Kysela, alsa-devel,
Takashi Iwai, Liam Girdwood
[-- Attachment #1: Type: text/plain, Size: 745 bytes --]
On Wed, Aug 23, 2017 at 07:42:55AM +0800, jeffy 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
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.
>
> 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..
>
> >
> > > + if (dai->driver->name &&
> > > + !strcmp(dai->driver->name, dlc->dai_name))
> >
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: Add a sanity check before using dai driver name
2017-08-23 11:06 ` Mark Brown
@ 2017-08-24 3:29 ` jeffy
2017-08-24 10:18 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: jeffy @ 2017-08-24 3:29 UTC (permalink / raw)
To: Mark Brown
Cc: linux-kernel, tiwai, dolinux.peng, Jaroslav Kysela, alsa-devel,
Takashi Iwai, Liam Girdwood
Hi Mark,
On 08/23/2017 07:06 PM, Mark Brown wrote:
> On Wed, Aug 23, 2017 at 07:42:55AM +0800, jeffy 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
> 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...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: Add a sanity check before using dai driver name
2017-08-24 3:29 ` jeffy
@ 2017-08-24 10:18 ` Mark Brown
2017-08-24 10:44 ` jeffy
0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2017-08-24 10:18 UTC (permalink / raw)
To: jeffy
Cc: linux-kernel, tiwai, dolinux.peng, Jaroslav Kysela, alsa-devel,
Takashi Iwai, Liam Girdwood
[-- Attachment #1: Type: text/plain, Size: 498 bytes --]
On Thu, Aug 24, 2017 at 11:29:42AM +0800, jeffy wrote:
> 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.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: Add a sanity check before using dai driver name
2017-08-24 10:18 ` Mark Brown
@ 2017-08-24 10:44 ` jeffy
0 siblings, 0 replies; 7+ messages in thread
From: jeffy @ 2017-08-24 10:44 UTC (permalink / raw)
To: Mark Brown
Cc: linux-kernel, tiwai, dolinux.peng, Jaroslav Kysela, alsa-devel,
Takashi Iwai, Liam Girdwood
hi Mark,
On 08/24/2017 06:18 PM, Mark Brown wrote:
> On Thu, Aug 24, 2017 at 11:29:42AM +0800, jeffy wrote:
>
>> 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.
right, i've already post a v3 for that ;)
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-08-24 10:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-22 14:45 [PATCH] ASoC: Add a sanity check before using dai driver name Jeffy Chen
2017-08-22 16:17 ` Mark Brown
2017-08-22 23:42 ` jeffy
2017-08-23 11:06 ` Mark Brown
2017-08-24 3:29 ` jeffy
2017-08-24 10:18 ` Mark Brown
2017-08-24 10:44 ` jeffy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).