diff mbox

[v5,2/9] ASoC: soc-core: Allow searching dai driver name in snd_soc_find_dai

Message ID 20170822075729.8438-3-jeffy.chen@rock-chips.com (mailing list archive)
State Accepted
Commit 4958471b0d2110a34df0b45803e6f24ed89b857b
Headers show

Commit Message

Jeffy Chen Aug. 22, 2017, 7:57 a.m. UTC
Currently we are searching dai name in snd_soc_find_dai, which could
either be dai driver name or component device name(for legacy naming).

Allow searching dai driver name in snd_soc_find_dai too, so that we can
use dai driver name to find legacy naming dais.

Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---

Changes in v5:
Allow searching for dai driver name in snd_soc_find_dai, instead of
hacking non-zero device id to avoid legay dai naming.

Changes in v4: None
Changes in v3: None
Changes in v2: None

 sound/soc/soc-core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Donglin Peng Aug. 22, 2017, 1:24 p.m. UTC | #1
Hi jeffy,

On Tue, Aug 22, 2017 at 3:57 PM, Jeffy Chen <jeffy.chen@rock-chips.com> wrote:

> @@ -978,7 +978,8 @@ 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))
> +                       if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)
> +                           && strcmp(dai->driver->name, dlc->dai_name))

In case that dai->driver->name is NULL, strcmp(dai->driver->name,
dlc->dai_name) will cause segmentation fault.
so I think that we can change it as the follows:

                      if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)
                           && dai->driver->name &&
strcmp(dai->driver->name, dlc->dai_name))

>                                 continue;
>
>                         return dai;
> --
> 2.11.0
>
>
Mark Brown Aug. 22, 2017, 2:02 p.m. UTC | #2
On Tue, Aug 22, 2017 at 09:24:32PM +0800, Donglin Peng wrote:

> In case that dai->driver->name is NULL, strcmp(dai->driver->name,
> dlc->dai_name) will cause segmentation fault.
> so I think that we can change it as the follows:

We should be already verifying that drivers have a name, we assume one
elsewhere.
Donglin Peng Aug. 22, 2017, 2:15 p.m. UTC | #3
On Tue, Aug 22, 2017 at 10:02 PM, Mark Brown <broonie@kernel.org> wrote:
> On Tue, Aug 22, 2017 at 09:24:32PM +0800, Donglin Peng wrote:
>
>> In case that dai->driver->name is NULL, strcmp(dai->driver->name,
>> dlc->dai_name) will cause segmentation fault.
>> so I think that we can change it as the follows:
>
> We should be already verifying that drivers have a name, we assume one
> elsewhere.

But I can't find any codes that set or check dai_driver->name in
function snd_soc_register_codec or snd_soc_register_component.
Mark Brown Aug. 22, 2017, 2:21 p.m. UTC | #4
On Tue, Aug 22, 2017 at 10:15:32PM +0800, Donglin Peng wrote:
> On Tue, Aug 22, 2017 at 10:02 PM, Mark Brown <broonie@kernel.org> wrote:

> > We should be already verifying that drivers have a name, we assume one
> > elsewhere.

> But I can't find any codes that set or check dai_driver->name in
> function snd_soc_register_codec or snd_soc_register_component.

We should fix that then.
Takashi Iwai Aug. 22, 2017, 2:26 p.m. UTC | #5
On Tue, 22 Aug 2017 16:21:11 +0200,
Mark Brown wrote:
> 
> On Tue, Aug 22, 2017 at 10:15:32PM +0800, Donglin Peng wrote:
> > On Tue, Aug 22, 2017 at 10:02 PM, Mark Brown <broonie@kernel.org> wrote:
> 
> > > We should be already verifying that drivers have a name, we assume one
> > > elsewhere.
> 
> > But I can't find any codes that set or check dai_driver->name in
> > function snd_soc_register_codec or snd_soc_register_component.
> 
> We should fix that then.

Hmm, as far as I read the code, the NULL dai driver name is valid for
a single component.  The dai name is determined by fmt_single_name().


Takashi
Mark Brown Aug. 22, 2017, 2:31 p.m. UTC | #6
On Tue, Aug 22, 2017 at 04:26:59PM +0200, Takashi Iwai wrote:
> Mark Brown wrote:

> > We should fix that then.

> Hmm, as far as I read the code, the NULL dai driver name is valid for
> a single component.  The dai name is determined by fmt_single_name().

We'll end up using it in debug stuff at some point, it's better to just
require something be there.  I don't expect us to require it for
matching.
Jeffy Chen Aug. 22, 2017, 2:39 p.m. UTC | #7
Hi guys,

On 08/22/2017 10:26 PM, Takashi Iwai wrote:
> On Tue, 22 Aug 2017 16:21:11 +0200,
> Mark Brown wrote:
>>
>> On Tue, Aug 22, 2017 at 10:15:32PM +0800, Donglin Peng wrote:
>>> On Tue, Aug 22, 2017 at 10:02 PM, Mark Brown <broonie@kernel.org> wrote:
>>
>>>> We should be already verifying that drivers have a name, we assume one
>>>> elsewhere.
>>
>>> But I can't find any codes that set or check dai_driver->name in
>>> function snd_soc_register_codec or snd_soc_register_component.
>>
>> We should fix that then.
>
> Hmm, as far as I read the code, the NULL dai driver name is valid for
> a single component.  The dai name is determined by fmt_single_name().
>
>
> Takashi
>
>
sorry, i though that is checked too... new patch is coming, thanks for 
noticing :)
>
diff mbox

Patch

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 004daaa82102..77e7e2a11af0 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -950,7 +950,7 @@  static struct snd_soc_component *soc_find_component(
 /**
  * snd_soc_find_dai - Find a registered DAI
  *
- * @dlc: name of the DAI and optional component info to match
+ * @dlc: name of the DAI or the DAI driver and optional component info to match
  *
  * This function will search all registered components and their DAIs to
  * find the DAI of the same name. The component's of_node and name
@@ -978,7 +978,8 @@  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))
+			if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)
+			    && strcmp(dai->driver->name, dlc->dai_name))
 				continue;
 
 			return dai;