Skip to content

Commit f48e7a2

Browse files
morimotobroonie
authored andcommitted
ASoC: soc-core: Use guard()/scoped_guard() for mutex lock
Replace the manual mutex lock/unlock pairs with guard()/scoped_guard(). Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://patch.msgid.link/875x7dac26.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 6dc41d8 commit f48e7a2

1 file changed

Lines changed: 24 additions & 44 deletions

File tree

sound/soc/soc-core.c

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -167,30 +167,24 @@ static int dai_list_show(struct seq_file *m, void *v)
167167
{
168168
struct snd_soc_component *component;
169169
struct snd_soc_dai *dai;
170-
171-
mutex_lock(&client_mutex);
170+
guard(mutex)(&client_mutex);
172171

173172
for_each_component(component)
174173
for_each_component_dais(component, dai)
175174
seq_printf(m, "%s\n", dai->name);
176175

177-
mutex_unlock(&client_mutex);
178-
179176
return 0;
180177
}
181178
DEFINE_SHOW_ATTRIBUTE(dai_list);
182179

183180
static int component_list_show(struct seq_file *m, void *v)
184181
{
185182
struct snd_soc_component *component;
186-
187-
mutex_lock(&client_mutex);
183+
guard(mutex)(&client_mutex);
188184

189185
for_each_component(component)
190186
seq_printf(m, "%s\n", component->name);
191187

192-
mutex_unlock(&client_mutex);
193-
194188
return 0;
195189
}
196190
DEFINE_SHOW_ATTRIBUTE(component_list);
@@ -394,13 +388,9 @@ EXPORT_SYMBOL_GPL(snd_soc_lookup_component_nolocked);
394388
struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
395389
const char *driver_name)
396390
{
397-
struct snd_soc_component *component;
398-
399-
mutex_lock(&client_mutex);
400-
component = snd_soc_lookup_component_nolocked(dev, driver_name);
401-
mutex_unlock(&client_mutex);
391+
guard(mutex)(&client_mutex);
402392

403-
return component;
393+
return snd_soc_lookup_component_nolocked(dev, driver_name);
404394
}
405395
EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
406396

@@ -950,13 +940,9 @@ EXPORT_SYMBOL_GPL(snd_soc_find_dai);
950940
struct snd_soc_dai *snd_soc_find_dai_with_mutex(
951941
const struct snd_soc_dai_link_component *dlc)
952942
{
953-
struct snd_soc_dai *dai;
954-
955-
mutex_lock(&client_mutex);
956-
dai = snd_soc_find_dai(dlc);
957-
mutex_unlock(&client_mutex);
943+
guard(mutex)(&client_mutex);
958944

959-
return dai;
945+
return snd_soc_find_dai(dlc);
960946
}
961947
EXPORT_SYMBOL_GPL(snd_soc_find_dai_with_mutex);
962948

@@ -2590,7 +2576,7 @@ int snd_soc_register_card(struct snd_soc_card *card)
25902576
mutex_init(&card->dapm_mutex);
25912577
mutex_init(&card->pcm_mutex);
25922578

2593-
mutex_lock(&client_mutex);
2579+
guard(mutex)(&client_mutex);
25942580

25952581
if (card->devres_dev) {
25962582
ret = devm_snd_soc_bind_card(card->devres_dev, card);
@@ -2602,8 +2588,6 @@ int snd_soc_register_card(struct snd_soc_card *card)
26022588
ret = snd_soc_bind_card(card);
26032589
}
26042590

2605-
mutex_unlock(&client_mutex);
2606-
26072591
return ret;
26082592
}
26092593
EXPORT_SYMBOL_GPL(snd_soc_register_card);
@@ -2616,10 +2600,11 @@ EXPORT_SYMBOL_GPL(snd_soc_register_card);
26162600
*/
26172601
void snd_soc_unregister_card(struct snd_soc_card *card)
26182602
{
2619-
mutex_lock(&client_mutex);
2603+
guard(mutex)(&client_mutex);
2604+
26202605
snd_soc_unbind_card(card);
26212606
list_del(&card->list);
2622-
mutex_unlock(&client_mutex);
2607+
26232608
dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
26242609
}
26252610
EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
@@ -2896,8 +2881,7 @@ int snd_soc_add_component(struct snd_soc_component *component,
28962881
struct snd_soc_card *card, *c;
28972882
int ret;
28982883
int i;
2899-
2900-
mutex_lock(&client_mutex);
2884+
guard(mutex)(&client_mutex);
29012885

29022886
if (component->driver->endianness) {
29032887
for (i = 0; i < num_dai; i++) {
@@ -2931,7 +2915,6 @@ int snd_soc_add_component(struct snd_soc_component *component,
29312915
if (ret < 0)
29322916
snd_soc_del_component_unlocked(component);
29332917

2934-
mutex_unlock(&client_mutex);
29352918
return ret;
29362919
}
29372920
EXPORT_SYMBOL_GPL(snd_soc_add_component);
@@ -2971,7 +2954,8 @@ void snd_soc_unregister_component_by_driver(struct device *dev,
29712954
if (component_driver)
29722955
driver_name = component_driver->name;
29732956

2974-
mutex_lock(&client_mutex);
2957+
guard(mutex)(&client_mutex);
2958+
29752959
while (1) {
29762960
struct snd_soc_component *component = snd_soc_lookup_component_nolocked(dev, driver_name);
29772961

@@ -2980,7 +2964,6 @@ void snd_soc_unregister_component_by_driver(struct device *dev,
29802964

29812965
snd_soc_del_component_unlocked(component);
29822966
}
2983-
mutex_unlock(&client_mutex);
29842967
}
29852968
EXPORT_SYMBOL_GPL(snd_soc_unregister_component_by_driver);
29862969

@@ -3516,7 +3499,6 @@ EXPORT_SYMBOL_GPL(snd_soc_get_stream_cpu);
35163499

35173500
int snd_soc_get_dai_id(struct device_node *ep)
35183501
{
3519-
struct snd_soc_component *component;
35203502
struct snd_soc_dai_link_component dlc = {
35213503
.of_node = of_graph_get_port_parent(ep),
35223504
};
@@ -3530,11 +3512,13 @@ int snd_soc_get_dai_id(struct device_node *ep)
35303512
* Then, it should have .of_xlate_dai_id
35313513
*/
35323514
ret = -ENOTSUPP;
3533-
mutex_lock(&client_mutex);
3534-
component = soc_find_component(&dlc);
3535-
if (component)
3536-
ret = snd_soc_component_of_xlate_dai_id(component, ep);
3537-
mutex_unlock(&client_mutex);
3515+
3516+
scoped_guard(mutex, &client_mutex) {
3517+
struct snd_soc_component *component = soc_find_component(&dlc);
3518+
3519+
if (component)
3520+
ret = snd_soc_component_of_xlate_dai_id(component, ep);
3521+
}
35383522

35393523
of_node_put(dlc.of_node);
35403524

@@ -3546,8 +3530,8 @@ int snd_soc_get_dlc(const struct of_phandle_args *args, struct snd_soc_dai_link_
35463530
{
35473531
struct snd_soc_component *pos;
35483532
int ret = -EPROBE_DEFER;
3533+
guard(mutex)(&client_mutex);
35493534

3550-
mutex_lock(&client_mutex);
35513535
for_each_component(pos) {
35523536
struct device_node *component_of_node = soc_component_to_node(pos);
35533537

@@ -3602,7 +3586,6 @@ int snd_soc_get_dlc(const struct of_phandle_args *args, struct snd_soc_dai_link_
36023586
if (ret == 0)
36033587
dlc->of_node = args->np;
36043588

3605-
mutex_unlock(&client_mutex);
36063589
return ret;
36073590
}
36083591
EXPORT_SYMBOL_GPL(snd_soc_get_dlc);
@@ -3657,17 +3640,14 @@ struct snd_soc_dai *snd_soc_get_dai_via_args(const struct of_phandle_args *dai_a
36573640
{
36583641
struct snd_soc_dai *dai;
36593642
struct snd_soc_component *component;
3643+
guard(mutex)(&client_mutex);
36603644

3661-
mutex_lock(&client_mutex);
36623645
for_each_component(component) {
36633646
for_each_component_dais(component, dai)
36643647
if (snd_soc_is_match_dai_args(dai->driver->dai_args, dai_args))
3665-
goto found;
3648+
return dai;
36663649
}
3667-
dai = NULL;
3668-
found:
3669-
mutex_unlock(&client_mutex);
3670-
return dai;
3650+
return NULL;
36713651
}
36723652
EXPORT_SYMBOL_GPL(snd_soc_get_dai_via_args);
36733653

0 commit comments

Comments
 (0)