diff mbox series

[v2,resend,03/18] ASoC: soc-core: tidyup soc_init_dai_link()

Message ID 87zhhjc9bw.wl-kuninori.morimoto.gx@renesas.com (mailing list archive)
State New, archived
Headers show
Series ASoC: soc-core cleanup - step 4 | expand

Commit Message

Kuninori Morimoto Oct. 30, 2019, 1:26 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

soc_init_dai_link() is needed to be called before soc_bind_dai_link().

	int snd_soc_instantiate_card()
	{
		for_each_card_prelinks(...) {
(1)			ret = soc_init_dai_link(...);
			...
		}
		...
		for_each_card_prelinks(...) {
(2)			ret = soc_bind_dai_link(...);
			...
		}
		...
		for_each_card_links(...) {
			...
(A)			ret = soc_init_dai_link(...);
			...
(B)			ret = soc_bind_dai_link(...);
		}
		...

(1) is for (2), and (A) is for (B)
(1) and (2) are for card prelink   dai_link.
(A) and (B) are for topology added dai_link.

soc_init_dai_link() is sanity check for dai_link, not initializing today.
Therefore, it is confusable naming. We can rename it as sanity_check.

And this check is for soc_bind_dai_link().
It can be more simple code if we can call it from soc_bind_dai_link().

This patch renames it to soc_dai_link_sanity_check(), and
call it from soc_bind_dai_link().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/soc-core.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

Comments

Ranjani Sridharan Nov. 5, 2019, 3:02 a.m. UTC | #1
On Wed, 2019-10-30 at 10:26 +0900, Kuninori Morimoto wrote:
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> soc_init_dai_link() is needed to be called before
> soc_bind_dai_link().
> 
> 	int snd_soc_instantiate_card()
> 	{
> 		for_each_card_prelinks(...) {
> (1)			ret = soc_init_dai_link(...);
> 			...
> 		}
> 		...
> 		for_each_card_prelinks(...) {
> (2)			ret = soc_bind_dai_link(...);
> 			...
> 		}
> 		...
> 		for_each_card_links(...) {
> 			...
> (A)			ret = soc_init_dai_link(...);
> 			...
> (B)			ret = soc_bind_dai_link(...);
> 		}
> 		...
> 
> (1) is for (2), and (A) is for (B)
> (1) and (2) are for card prelink   dai_link.
> (A) and (B) are for topology added dai_link.
> 
> soc_init_dai_link() is sanity check for dai_link, not initializing
> today.
> Therefore, it is confusable naming. We can rename it as sanity_check.
> 
> And this check is for soc_bind_dai_link().
> It can be more simple code if we can call it from
> soc_bind_dai_link().
> 
> This patch renames it to soc_dai_link_sanity_check(), and
> call it from soc_bind_dai_link().
> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> ---
>  sound/soc/soc-core.c | 22 +++++++---------------
>  1 file changed, 7 insertions(+), 15 deletions(-)
> 
> diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
> index a141828..94763fc9c 100644
> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -941,8 +941,8 @@ static bool soc_is_dai_link_bound(struct
> snd_soc_card *card,
>  	return false;
>  }
>  
> -static int soc_init_dai_link(struct snd_soc_card *card,
> -			     struct snd_soc_dai_link *link)
> +static int soc_dai_link_sanity_check(struct snd_soc_card *card,
> +				     struct snd_soc_dai_link *link)
>  {
>  	int i;
>  	struct snd_soc_dai_link_component *codec, *platform;
> @@ -1043,11 +1043,15 @@ static int soc_bind_dai_link(struct
> snd_soc_card *card,
>  	struct snd_soc_pcm_runtime *rtd;
>  	struct snd_soc_dai_link_component *codec, *platform;
>  	struct snd_soc_component *component;
> -	int i;
> +	int i, ret;
>  
>  	if (dai_link->ignore)
>  		return 0;
>  
> +	ret = soc_dai_link_sanity_check(card, dai_link);
> +	if (ret < 0)
> +		return ret;
Morimoto-san,

Should this be done after checking if soc_is_dai_link_bound() maybe?

Thanks,
Ranjani
> +
>  	dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
>  
>  	if (soc_is_dai_link_bound(card, dai_link)) {
> @@ -1985,15 +1989,6 @@ static int snd_soc_instantiate_card(struct
> snd_soc_card *card)
>  	int ret, i;
>  
>  	mutex_lock(&client_mutex);
> -	for_each_card_prelinks(card, i, dai_link) {
> -		ret = soc_init_dai_link(card, dai_link);
> -		if (ret) {
> -			dev_err(card->dev, "ASoC: failed to init link
> %s: %d\n",
> -				dai_link->name, ret);
> -			mutex_unlock(&client_mutex);
> -			return ret;
> -		}
> -	}
>  	mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
>  
>  	snd_soc_dapm_init(&card->dapm, card, NULL);
> @@ -2073,9 +2068,6 @@ static int snd_soc_instantiate_card(struct
> snd_soc_card *card)
>  		if (soc_is_dai_link_bound(card, dai_link))
>  			continue;
>  
> -		ret = soc_init_dai_link(card, dai_link);
> -		if (ret)
> -			goto probe_end;
>  		ret = soc_bind_dai_link(card, dai_link);
>  		if (ret)
>  			goto probe_end;
Kuninori Morimoto Nov. 5, 2019, 4:19 a.m. UTC | #2
Hi Ranjani

Thank you for your review.

> > +static int soc_dai_link_sanity_check(struct snd_soc_card *card,
> > +				     struct snd_soc_dai_link *link)
> >  {
> >  	int i;
> >  	struct snd_soc_dai_link_component *codec, *platform;
> > @@ -1043,11 +1043,15 @@ static int soc_bind_dai_link(struct
> > snd_soc_card *card,
> >  	struct snd_soc_pcm_runtime *rtd;
> >  	struct snd_soc_dai_link_component *codec, *platform;
> >  	struct snd_soc_component *component;
> > -	int i;
> > +	int i, ret;
> >  
> >  	if (dai_link->ignore)
> >  		return 0;
> >  
> > +	ret = soc_dai_link_sanity_check(card, dai_link);
> > +	if (ret < 0)
> > +		return ret;
> Morimoto-san,
> 
> Should this be done after checking if soc_is_dai_link_bound() maybe?

Hmm... maybe
Thanks. I will fixit in v3

Thank you for your help !!
Best regards
---
Kuninori Morimoto
Sridharan, Ranjani Nov. 5, 2019, 5:22 a.m. UTC | #3
On Mon, Nov 4, 2019 at 8:21 PM Kuninori Morimoto <
kuninori.morimoto.gx@renesas.com> wrote:

>
> Hi Ranjani
>
> Thank you for your review.
>
> > > +static int soc_dai_link_sanity_check(struct snd_soc_card *card,
> > > +                                struct snd_soc_dai_link *link)
> > >  {
> > >     int i;
> > >     struct snd_soc_dai_link_component *codec, *platform;
> > > @@ -1043,11 +1043,15 @@ static int soc_bind_dai_link(struct
> > > snd_soc_card *card,
> > >     struct snd_soc_pcm_runtime *rtd;
> > >     struct snd_soc_dai_link_component *codec, *platform;
> > >     struct snd_soc_component *component;
> > > -   int i;
> > > +   int i, ret;
> > >
> > >     if (dai_link->ignore)
> > >             return 0;
> > >
> > > +   ret = soc_dai_link_sanity_check(card, dai_link);
> > > +   if (ret < 0)
> > > +           return ret;
> > Morimoto-san,
> >
> > Should this be done after checking if soc_is_dai_link_bound() maybe?
>
Morimoto-san,

I thought about this a bit more. With you changes in the series to move
bind_dai_link() to snd_soc_add_dai(), is the check
for soc_is_dai_link_bound() needed at all?

Thanks,
Ranjani

>
> Hmm... maybe
> Thanks. I will fixit in v3
>
> Thank you for your help !!
> Best regards
> ---
> Kuninori Morimoto
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
>
Kuninori Morimoto Nov. 5, 2019, 5:35 a.m. UTC | #4
Hi Sridharan

Thank you for your review

>     > > +static int soc_dai_link_sanity_check(struct snd_soc_card *card,
>     > > +                                struct snd_soc_dai_link *link)
>     > >  {
>     > >     int i;
>     > >     struct snd_soc_dai_link_component *codec, *platform;
>     > > @@ -1043,11 +1043,15 @@ static int soc_bind_dai_link(struct
>     > > snd_soc_card *card,
>     > >     struct snd_soc_pcm_runtime *rtd;
>     > >     struct snd_soc_dai_link_component *codec, *platform;
>     > >     struct snd_soc_component *component;
>     > > -   int i;
>     > > +   int i, ret;
>     > > 
>     > >     if (dai_link->ignore)
>     > >             return 0;
>     > > 
>     > > +   ret = soc_dai_link_sanity_check(card, dai_link);
>     > > +   if (ret < 0)
>     > > +           return ret;
>     > Morimoto-san,
>     >
>     > Should this be done after checking if soc_is_dai_link_bound() maybe?
> 
> Morimoto-san,
> 
> I thought about this a bit more. With you changes in the series to move bind_dai_link() to snd_soc_add_dai(), is the check
> for soc_is_dai_link_bound() needed at all?

soc_is_dai_link_bound() is no longer needed.
It will be removed in my *next* patch-set.
Is this clear answer for you ?

Thank you for your help !!
Best regards
---
Kuninori Morimoto
diff mbox series

Patch

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index a141828..94763fc9c 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -941,8 +941,8 @@  static bool soc_is_dai_link_bound(struct snd_soc_card *card,
 	return false;
 }
 
-static int soc_init_dai_link(struct snd_soc_card *card,
-			     struct snd_soc_dai_link *link)
+static int soc_dai_link_sanity_check(struct snd_soc_card *card,
+				     struct snd_soc_dai_link *link)
 {
 	int i;
 	struct snd_soc_dai_link_component *codec, *platform;
@@ -1043,11 +1043,15 @@  static int soc_bind_dai_link(struct snd_soc_card *card,
 	struct snd_soc_pcm_runtime *rtd;
 	struct snd_soc_dai_link_component *codec, *platform;
 	struct snd_soc_component *component;
-	int i;
+	int i, ret;
 
 	if (dai_link->ignore)
 		return 0;
 
+	ret = soc_dai_link_sanity_check(card, dai_link);
+	if (ret < 0)
+		return ret;
+
 	dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
 
 	if (soc_is_dai_link_bound(card, dai_link)) {
@@ -1985,15 +1989,6 @@  static int snd_soc_instantiate_card(struct snd_soc_card *card)
 	int ret, i;
 
 	mutex_lock(&client_mutex);
-	for_each_card_prelinks(card, i, dai_link) {
-		ret = soc_init_dai_link(card, dai_link);
-		if (ret) {
-			dev_err(card->dev, "ASoC: failed to init link %s: %d\n",
-				dai_link->name, ret);
-			mutex_unlock(&client_mutex);
-			return ret;
-		}
-	}
 	mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
 
 	snd_soc_dapm_init(&card->dapm, card, NULL);
@@ -2073,9 +2068,6 @@  static int snd_soc_instantiate_card(struct snd_soc_card *card)
 		if (soc_is_dai_link_bound(card, dai_link))
 			continue;
 
-		ret = soc_init_dai_link(card, dai_link);
-		if (ret)
-			goto probe_end;
 		ret = soc_bind_dai_link(card, dai_link);
 		if (ret)
 			goto probe_end;