diff mbox series

[03/11] ASoC: atmel: mchp-pdmc: Use snd_ctl_remove_id()

Message ID 20230718141304.1032-4-tiwai@suse.de
State Accepted
Commit d8b366c40638d5aedad74646707b2b04b7342210
Headers show
Series ALSA: Make control API taking controls_rwsem consistently | expand

Commit Message

Takashi Iwai July 18, 2023, 2:12 p.m. UTC
Use the standard snd_ctl_remove_id() helper instead of open code for
removing a kctl.  This helps for avoiding possible races.

Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/atmel/mchp-pdmc.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

Comments

Claudiu Beznea July 18, 2023, 2:45 p.m. UTC | #1
On 18.07.2023 17:12, Takashi Iwai wrote:
> Use the standard snd_ctl_remove_id() helper instead of open code for
> removing a kctl.  This helps for avoiding possible races.
> 
> Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
> Cc: Mark Brown <broonie@kernel.org>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>

Reviewed-by: Claudiu Beznea <claudiu.beznea@tuxon.dev>

> ---
>   sound/soc/atmel/mchp-pdmc.c | 12 ++----------
>   1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/sound/soc/atmel/mchp-pdmc.c b/sound/soc/atmel/mchp-pdmc.c
> index c79c73e6791e..1a069f4cdcda 100644
> --- a/sound/soc/atmel/mchp-pdmc.c
> +++ b/sound/soc/atmel/mchp-pdmc.c
> @@ -386,7 +386,6 @@ static int mchp_pdmc_open(struct snd_soc_component *component,
>   	for (i = 0; i < ARRAY_SIZE(mchp_pdmc_snd_controls); i++) {
>   		const struct snd_kcontrol_new *control = &mchp_pdmc_snd_controls[i];
>   		struct snd_ctl_elem_id id;
> -		struct snd_kcontrol *kctl;
>   		int err;
>   
>   		if (component->name_prefix)
> @@ -400,17 +399,10 @@ static int mchp_pdmc_open(struct snd_soc_component *component,
>   		id.device = control->device;
>   		id.subdevice = control->subdevice;
>   		id.index = control->index;
> -		kctl = snd_ctl_find_id(component->card->snd_card, &id);
> -		if (!kctl) {
> -			dev_err(component->dev, "Failed to find %s\n", control->name);
> -			continue;
> -		}
> -		err = snd_ctl_remove(component->card->snd_card, kctl);
> -		if (err < 0) {
> +		err = snd_ctl_remove_id(component->card->snd_card, &id);
> +		if (err < 0)
>   			dev_err(component->dev, "%d: Failed to remove %s\n", err,
>   				control->name);
> -			continue;
> -		}
>   	}
>   
>   	return 0;
diff mbox series

Patch

diff --git a/sound/soc/atmel/mchp-pdmc.c b/sound/soc/atmel/mchp-pdmc.c
index c79c73e6791e..1a069f4cdcda 100644
--- a/sound/soc/atmel/mchp-pdmc.c
+++ b/sound/soc/atmel/mchp-pdmc.c
@@ -386,7 +386,6 @@  static int mchp_pdmc_open(struct snd_soc_component *component,
 	for (i = 0; i < ARRAY_SIZE(mchp_pdmc_snd_controls); i++) {
 		const struct snd_kcontrol_new *control = &mchp_pdmc_snd_controls[i];
 		struct snd_ctl_elem_id id;
-		struct snd_kcontrol *kctl;
 		int err;
 
 		if (component->name_prefix)
@@ -400,17 +399,10 @@  static int mchp_pdmc_open(struct snd_soc_component *component,
 		id.device = control->device;
 		id.subdevice = control->subdevice;
 		id.index = control->index;
-		kctl = snd_ctl_find_id(component->card->snd_card, &id);
-		if (!kctl) {
-			dev_err(component->dev, "Failed to find %s\n", control->name);
-			continue;
-		}
-		err = snd_ctl_remove(component->card->snd_card, kctl);
-		if (err < 0) {
+		err = snd_ctl_remove_id(component->card->snd_card, &id);
+		if (err < 0)
 			dev_err(component->dev, "%d: Failed to remove %s\n", err,
 				control->name);
-			continue;
-		}
 	}
 
 	return 0;