diff mbox series

[12/21] ASoC: soc-core: use snd_soc_lookup_component() at snd_soc_unregister_component()

Message ID 87bluqilqm.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. 9, 2019, 4:30 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

snd_soc_unregister_component() is now finding component manually,
but we already have snd_soc_lookup_component() to find component;
Let's use existing function.

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

Comments

Pierre-Louis Bossart Oct. 10, 2019, 3:19 p.m. UTC | #1
On 10/8/19 11:30 PM, Kuninori Morimoto wrote:
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> snd_soc_unregister_component() is now finding component manually,
> but we already have snd_soc_lookup_component() to find component;
> Let's use existing function.
> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> ---
>   sound/soc/soc-core.c | 25 +++++++------------------
>   1 file changed, 7 insertions(+), 18 deletions(-)
> 
> diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
> index 7c0bb32..3e8ed4f 100644
> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -2823,8 +2823,10 @@ static void snd_soc_try_rebind_card(void)
>   
>   static void snd_soc_del_component(struct snd_soc_component *component)
>   {
> +	mutex_lock(&client_mutex);
>   	snd_soc_unregister_dais(component);
>   	snd_soc_component_del(component);
> +	mutex_unlock(&client_mutex);
>   }
>   
>   int snd_soc_add_component(struct device *dev,
> @@ -2887,29 +2889,16 @@ EXPORT_SYMBOL_GPL(snd_soc_register_component);
>    *
>    * @dev: The device to unregister
>    */
> -static int __snd_soc_unregister_component(struct device *dev)
> +void snd_soc_unregister_component(struct device *dev)
>   {
>   	struct snd_soc_component *component;
> -	int found = 0;
> -
> -	mutex_lock(&client_mutex);
> -	for_each_component(component) {
> -		if (dev != component->dev)
> -			continue;
>   
> +	while (1) {
> +		component = snd_soc_lookup_component(dev, NULL);
> +		if (!component)
> +			break;
>   		snd_soc_del_component(component);

is it ok/intended that the mutex lock is now taken *after* looking up 
the component and after each iteration ?

> -		found = 1;
> -		break;
>   	}
> -	mutex_unlock(&client_mutex);
> -
> -	return found;
> -}
> -
> -void snd_soc_unregister_component(struct device *dev)
> -{
> -	while (__snd_soc_unregister_component(dev))
> -		;
>   }
>   EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
>   
>
Kuninori Morimoto Oct. 11, 2019, 1:38 a.m. UTC | #2
Hi Pierre-Louis

> > +void snd_soc_unregister_component(struct device *dev)
> >   {
> >   	struct snd_soc_component *component;
> > -	int found = 0;
> > -
> > -	mutex_lock(&client_mutex);
> > -	for_each_component(component) {
> > -		if (dev != component->dev)
> > -			continue;
> >   +	while (1) {
> > +		component = snd_soc_lookup_component(dev, NULL);
> > +		if (!component)
> > +			break;
> >   		snd_soc_del_component(component);
> 
> is it ok/intended that the mutex lock is now taken *after* looking up
> the component and after each iteration ?

Hmm.. maybe not good.
I will keep _unlocked() naming and mutex

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 7c0bb32..3e8ed4f 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2823,8 +2823,10 @@  static void snd_soc_try_rebind_card(void)
 
 static void snd_soc_del_component(struct snd_soc_component *component)
 {
+	mutex_lock(&client_mutex);
 	snd_soc_unregister_dais(component);
 	snd_soc_component_del(component);
+	mutex_unlock(&client_mutex);
 }
 
 int snd_soc_add_component(struct device *dev,
@@ -2887,29 +2889,16 @@  EXPORT_SYMBOL_GPL(snd_soc_register_component);
  *
  * @dev: The device to unregister
  */
-static int __snd_soc_unregister_component(struct device *dev)
+void snd_soc_unregister_component(struct device *dev)
 {
 	struct snd_soc_component *component;
-	int found = 0;
-
-	mutex_lock(&client_mutex);
-	for_each_component(component) {
-		if (dev != component->dev)
-			continue;
 
+	while (1) {
+		component = snd_soc_lookup_component(dev, NULL);
+		if (!component)
+			break;
 		snd_soc_del_component(component);
-		found = 1;
-		break;
 	}
-	mutex_unlock(&client_mutex);
-
-	return found;
-}
-
-void snd_soc_unregister_component(struct device *dev)
-{
-	while (__snd_soc_unregister_component(dev))
-		;
 }
 EXPORT_SYMBOL_GPL(snd_soc_unregister_component);