ASoC: tidyup card rebind functions
cover ASoC: tidyup card rebind functions
Hi Mar, Cezary
Now, all user can use deferrable card binding.
Now soc-core.c file has handling Card/Component/DAI randomly, so I would like to capsuling these into soc-card/dai/component.c files.
So, I would like to handle Card related things in xx_card_xx() function. It is easy to move functions when capsuling.
This patch tidyup deferrable card binding. No functional change.
Kuninori Morimoto (2):
ASoC: soc-core: add soc_rebind_card()
ASoC: soc-core: handle card->list in snd_soc_unbind_card()
sound/soc/soc-core.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 ASoC: soc-core: add soc_rebind_card()
snd_soc_add_component() try to rebind Card. Which can be done as Card function. Let's add soc_rebind_card() for it.
--- sound/soc/soc-core.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
sound/soc/soc-core.c +9 -3
@@ -2197,6 +2197,14 @@ static int call_soc_bind_card(struct snd_soc_card *card)return snd_soc_bind_card (card); } +static void soc_rebind_card (void ) +{ +struct snd_soc_card *card, *c; + +list_for_each_entry_safe (card, c, &unbind_card_list, list) +call_soc_bind_card (card); +} +/* probes a new socdev */ static int soc_probe (struct platform_device *pdev) {
@@ -2708,7 +2716,6 @@ int snd_soc_add_component(struct snd_soc_component *component,struct snd_soc_dai_driver *dai_drv, int num_dai) { -struct snd_soc_card *card, *c; int ret;int i;guard (mutex)(&client_mutex);
@@ -2736,8 +2743,7 @@ int snd_soc_add_component(struct snd_soc_component *component,/* see for_each_component */ list_add (&component->list, &component_list); -list_for_each_entry_safe (card, c, &unbind_card_list, list) -call_soc_bind_card (card); +soc_rebind_card (); err_cleanup:if (ret <0 )
Signature · 1 line
2.43.0
Re: [PATCH 1/2] ASoC: soc-core: add soc_rebind_card()
Quoted 36 lines · Kuninori Morimoto
snd_soc_add_component()try to rebind Card. Which can be done as Card function. Let's addsoc_rebind_card()for it.Signed-off-by Kuninori Morimoto <[email protected]>--- sound/soc/soc-core.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)sound/soc/soc-core.c +8
-1@@ -2197,6 +2197,14 @@ static int call_soc_bind_card(struct snd_soc_card *card)return snd_soc_bind_card (card); } +static void soc_rebind_card (void ) +{ +struct snd_soc_card *card, *c; + +list_for_each_entry_safe (card, c, &unbind_card_list, list) +call_soc_bind_card (card); +} +/* probes a new socdev */ static int soc_probe (struct platform_device *pdev) {@@ -2708,7 +2716,6 @@ int snd_soc_add_component(struct snd_soc_component *component,struct snd_soc_dai_driver *dai_drv, int num_dai) { -struct snd_soc_card *card, *c; int ret;int i;guard (mutex)(&client_mutex);
sound/soc/soc-core.c int snd_soc_add_component(struct snd_soc_component *component, · line 2746
Quoted 6 lines
sound/soc/soc-core.c +1
-2@@ -2736,8 +2743,7 @@ int snd_soc_add_component(struct snd_soc_component *component,/* see for_each_component */ list_add (&component->list, &component_list); -list_for_each_entry_safe (card, c, &unbind_card_list, list) -call_soc_bind_card (card); +soc_rebind_card ();
The naming is off. Clearly, we're not dealing with a card - many cards could be bound here.
As previous patches related to the subject removed the rebind_card() function, I'm not sure we want it back. Perhaps a readable macro instead?
#define for_each_unbound_card(card, c)
list_for_each_entry_safe(card, c, &unbind_card_list, list)
Quoted 3 lines
sound/soc/soc-core.c +0
-0err_cleanup:if (ret <0 )
Re: [PATCH 1/2] ASoC: soc-core: add soc_rebind_card()
Hi Rojewski
Thank you for your review
Quoted 10 lines
sound/soc/soc-core.c int snd_soc_add_component(struct snd_soc_component *component, · line 2746
Quoted 1 line
sound/soc/soc-core.c +1
-0+soc_rebind_card ();The naming is off. Clearly, we're not dealing with a card - many cards could be bound here.
As previous patches related to the subject removed the
rebind_card()function, I'm not sure we want it back. Perhaps a readable macro instead?#define
for_each_unbound_card(card, c)
list_for_each_entry_safe(card, c, &unbind_card_list, list)
Biggest concern here is that snd_soc_add_component() will goes to soc-component.c, and it can't use "unbind_card_list" which will goto soc-card.c as local variable (because of capsuling).
So, using #define is not enough. We would like to makes it as "card function", and call it from soc-component.c.
How about "soc_try_bind_card_all()" or something ?
Note is that I would like to rename card function as "[snd_]soc_card_xxx()" when it goes to soc-card.c
ex)
soc_bind_card() -> soc_card_bind() soc_unbind_card() -> soc_card_unbind() soc_try_bind_card_all() -> soc_card_try_bind_all()
Thank you for your help !!
Best regards
---
Kuninori Morimoto
PATCH 2/2 ASoC: soc-core: handle card->list in snd_soc_unbind_card()
In reply to Kuninori Morimotosnd_soc_bind_card() is handling card->list inside, butsnd_soc_unbind_card() is handling it in outside.
Let's handle it inside.
--- sound/soc/soc-core.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
sound/soc/soc-core.c +10 -9
@@ -1990,12 +1990,18 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card) } } -static void snd_soc_unbind_card (struct snd_soc_card *card) +static void snd_soc_unbind_card (struct snd_soc_card *card,bool add_to_list) {if (snd_soc_card_is_instantiated (card)) { card->instantiated = false;soc_cleanup_card_resources (card); + +if (add_to_list) +list_add (&card->list, &unbind_card_list); } + +if (!add_to_list) +list_del (&card->list); }static int snd_soc_bind_card (struct snd_soc_card *card)
@@ -2439,8 +2445,7 @@ void snd_soc_unregister_card(struct snd_soc_card *card) {guard (mutex)(&client_mutex); -snd_soc_unbind_card (card); -list_del (&card->list); +snd_soc_unbind_card (card, false);dev_dbg (card->dev,"ASoC: Unregistered card '%s'\n" , card->name); }
@@ -2667,12 +2672,8 @@ static void snd_soc_del_component_unlocked(struct snd_soc_component *component)snd_soc_unregister_dais (component); -if (card) { - instantiated = card->instantiated; -snd_soc_unbind_card (card); -if (instantiated) -list_add (&card->list, &unbind_card_list); - } +if (card) +snd_soc_unbind_card (card, true);list_del (&component->list); }
Signature · 1 line
2.43.0
Re: [PATCH 2/2] ASoC: soc-core: handle card->list in snd_soc_unbind_card()
Quoted 16 lines · Kuninori Morimoto
snd_soc_bind_card()is handlingcard->listinside, butsnd_soc_unbind_card()is handling it in outside.
Let's handle it inside.Signed-off-by Kuninori Morimoto <[email protected]>--- sound/soc/soc-core.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)sound/soc/soc-core.c +0
-0@@ -1990,12 +1990,18 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card) } }
sound/soc/soc-core.c static void soc_cleanup_card_resources(struct snd_soc_card *card) · line 2000
Quoted 10 lines
sound/soc/soc-core.c +4
-1-static void snd_soc_unbind_card (struct snd_soc_card *card) +static void snd_soc_unbind_card (struct snd_soc_card *card,bool add_to_list) {if (snd_soc_card_is_instantiated (card)) { card->instantiated = false;soc_cleanup_card_resources (card); + +if (add_to_list) +list_add (&card->list, &unbind_card_list);
I see benefit in this.
sound/soc/soc-core.c static void soc_cleanup_card_resources(struct snd_soc_card *card) · line 2004
Quoted 4 lines
sound/soc/soc-core.c +3
-0} + +if (!add_to_list) +list_del (&card->list);
But not this.
Moving card-behavior code from component-related function to card-related one seems intuitive. However, snd_soc_unregister_card() is already card-lated function. I'd keep the list_del() there and avoid the second if-statement.
Quoted 28 lines
sound/soc/soc-core.c +3
-8}static int snd_soc_bind_card (struct snd_soc_card *card)@@ -2439,8 +2445,7 @@ void snd_soc_unregister_card(struct snd_soc_card *card) {guard (mutex)(&client_mutex); -snd_soc_unbind_card (card); -list_del (&card->list); +snd_soc_unbind_card (card, false);dev_dbg (card->dev,"ASoC: Unregistered card '%s'\n" , card->name); }@@ -2667,12 +2672,8 @@ static void snd_soc_del_component_unlocked(struct snd_soc_component *component)snd_soc_unregister_dais (component); -if (card) { - instantiated = card->instantiated; -snd_soc_unbind_card (card); -if (instantiated) -list_add (&card->list, &unbind_card_list); - } +if (card) +snd_soc_unbind_card (card, true);list_del (&component->list); }
Re: [PATCH 2/2] ASoC: soc-core: handle card->list in snd_soc_unbind_card()
Hi Rojewski
Thank you for your feedback.
Quoted 9 lines
sound/soc/soc-core.c static void soc_cleanup_card_resources(struct snd_soc_card *card) · line 2004
Quoted 2 lines
sound/soc/soc-core.c +2
-0+if (!add_to_list) +list_del (&card->list);But not this.
Moving card-behavior code from component-related function to card-related one seems intuitive. However,
snd_soc_unregister_card()is already card-lated function. I'd keep thelist_del()there and avoid the second if-statement.
I can agree if we focus about "whether card-lated function" or not. But if we focus to contrast/balance of functions, it is...
(*) hadling list
register <-> unregister (*) bind (*) <-> unbind (*)
This is not good balance. I like
register <-> unregister bind (*) <-> unbind (*)
But indeed, I can agree that having bool in unbind function is not a bad idea, but not so good...
And, 2nd concern is that snd_soc_unregister_card() is using client_mutex. It is soc-core.c local variable. So snd_soc_unregister_card() might can't goto soc-card.c. This means we need to include card->list handling inside soc_unbind_card() and call it from soc-core.c.
(Or maybe we can share client_mutex on each soc-xxx.c, but not sure yet).
But what do you think ?
Thank you for your help !!
Best regards
---
Kuninori Morimoto