Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Kuninori Morimoto and committed by
Mark Brown
f48e7a24 6dc41d8d

+24 -44
+24 -44
sound/soc/soc-core.c
··· 167 167 { 168 168 struct snd_soc_component *component; 169 169 struct snd_soc_dai *dai; 170 - 171 - mutex_lock(&client_mutex); 170 + guard(mutex)(&client_mutex); 172 171 173 172 for_each_component(component) 174 173 for_each_component_dais(component, dai) 175 174 seq_printf(m, "%s\n", dai->name); 176 - 177 - mutex_unlock(&client_mutex); 178 175 179 176 return 0; 180 177 } ··· 180 183 static int component_list_show(struct seq_file *m, void *v) 181 184 { 182 185 struct snd_soc_component *component; 183 - 184 - mutex_lock(&client_mutex); 186 + guard(mutex)(&client_mutex); 185 187 186 188 for_each_component(component) 187 189 seq_printf(m, "%s\n", component->name); 188 - 189 - mutex_unlock(&client_mutex); 190 190 191 191 return 0; 192 192 } ··· 388 394 struct snd_soc_component *snd_soc_lookup_component(struct device *dev, 389 395 const char *driver_name) 390 396 { 391 - struct snd_soc_component *component; 397 + guard(mutex)(&client_mutex); 392 398 393 - mutex_lock(&client_mutex); 394 - component = snd_soc_lookup_component_nolocked(dev, driver_name); 395 - mutex_unlock(&client_mutex); 396 - 397 - return component; 399 + return snd_soc_lookup_component_nolocked(dev, driver_name); 398 400 } 399 401 EXPORT_SYMBOL_GPL(snd_soc_lookup_component); 400 402 ··· 940 950 struct snd_soc_dai *snd_soc_find_dai_with_mutex( 941 951 const struct snd_soc_dai_link_component *dlc) 942 952 { 943 - struct snd_soc_dai *dai; 953 + guard(mutex)(&client_mutex); 944 954 945 - mutex_lock(&client_mutex); 946 - dai = snd_soc_find_dai(dlc); 947 - mutex_unlock(&client_mutex); 948 - 949 - return dai; 955 + return snd_soc_find_dai(dlc); 950 956 } 951 957 EXPORT_SYMBOL_GPL(snd_soc_find_dai_with_mutex); 952 958 ··· 2576 2590 mutex_init(&card->dapm_mutex); 2577 2591 mutex_init(&card->pcm_mutex); 2578 2592 2579 - mutex_lock(&client_mutex); 2593 + guard(mutex)(&client_mutex); 2580 2594 2581 2595 if (card->devres_dev) { 2582 2596 ret = devm_snd_soc_bind_card(card->devres_dev, card); ··· 2587 2601 } else { 2588 2602 ret = snd_soc_bind_card(card); 2589 2603 } 2590 - 2591 - mutex_unlock(&client_mutex); 2592 2604 2593 2605 return ret; 2594 2606 } ··· 2600 2616 */ 2601 2617 void snd_soc_unregister_card(struct snd_soc_card *card) 2602 2618 { 2603 - mutex_lock(&client_mutex); 2619 + guard(mutex)(&client_mutex); 2620 + 2604 2621 snd_soc_unbind_card(card); 2605 2622 list_del(&card->list); 2606 - mutex_unlock(&client_mutex); 2623 + 2607 2624 dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name); 2608 2625 } 2609 2626 EXPORT_SYMBOL_GPL(snd_soc_unregister_card); ··· 2881 2896 struct snd_soc_card *card, *c; 2882 2897 int ret; 2883 2898 int i; 2884 - 2885 - mutex_lock(&client_mutex); 2899 + guard(mutex)(&client_mutex); 2886 2900 2887 2901 if (component->driver->endianness) { 2888 2902 for (i = 0; i < num_dai; i++) { ··· 2915 2931 if (ret < 0) 2916 2932 snd_soc_del_component_unlocked(component); 2917 2933 2918 - mutex_unlock(&client_mutex); 2919 2934 return ret; 2920 2935 } 2921 2936 EXPORT_SYMBOL_GPL(snd_soc_add_component); ··· 2954 2971 if (component_driver) 2955 2972 driver_name = component_driver->name; 2956 2973 2957 - mutex_lock(&client_mutex); 2974 + guard(mutex)(&client_mutex); 2975 + 2958 2976 while (1) { 2959 2977 struct snd_soc_component *component = snd_soc_lookup_component_nolocked(dev, driver_name); 2960 2978 ··· 2964 2980 2965 2981 snd_soc_del_component_unlocked(component); 2966 2982 } 2967 - mutex_unlock(&client_mutex); 2968 2983 } 2969 2984 EXPORT_SYMBOL_GPL(snd_soc_unregister_component_by_driver); 2970 2985 ··· 3499 3516 3500 3517 int snd_soc_get_dai_id(struct device_node *ep) 3501 3518 { 3502 - struct snd_soc_component *component; 3503 3519 struct snd_soc_dai_link_component dlc = { 3504 3520 .of_node = of_graph_get_port_parent(ep), 3505 3521 }; ··· 3512 3530 * Then, it should have .of_xlate_dai_id 3513 3531 */ 3514 3532 ret = -ENOTSUPP; 3515 - mutex_lock(&client_mutex); 3516 - component = soc_find_component(&dlc); 3517 - if (component) 3518 - ret = snd_soc_component_of_xlate_dai_id(component, ep); 3519 - mutex_unlock(&client_mutex); 3533 + 3534 + scoped_guard(mutex, &client_mutex) { 3535 + struct snd_soc_component *component = soc_find_component(&dlc); 3536 + 3537 + if (component) 3538 + ret = snd_soc_component_of_xlate_dai_id(component, ep); 3539 + } 3520 3540 3521 3541 of_node_put(dlc.of_node); 3522 3542 ··· 3530 3546 { 3531 3547 struct snd_soc_component *pos; 3532 3548 int ret = -EPROBE_DEFER; 3549 + guard(mutex)(&client_mutex); 3533 3550 3534 - mutex_lock(&client_mutex); 3535 3551 for_each_component(pos) { 3536 3552 struct device_node *component_of_node = soc_component_to_node(pos); 3537 3553 ··· 3586 3602 if (ret == 0) 3587 3603 dlc->of_node = args->np; 3588 3604 3589 - mutex_unlock(&client_mutex); 3590 3605 return ret; 3591 3606 } 3592 3607 EXPORT_SYMBOL_GPL(snd_soc_get_dlc); ··· 3640 3657 { 3641 3658 struct snd_soc_dai *dai; 3642 3659 struct snd_soc_component *component; 3660 + guard(mutex)(&client_mutex); 3643 3661 3644 - mutex_lock(&client_mutex); 3645 3662 for_each_component(component) { 3646 3663 for_each_component_dais(component, dai) 3647 3664 if (snd_soc_is_match_dai_args(dai->driver->dai_args, dai_args)) 3648 - goto found; 3665 + return dai; 3649 3666 } 3650 - dai = NULL; 3651 - found: 3652 - mutex_unlock(&client_mutex); 3653 - return dai; 3667 + return NULL; 3654 3668 } 3655 3669 EXPORT_SYMBOL_GPL(snd_soc_get_dai_via_args); 3656 3670