Re: [PATCH 18/26] ASoC: codecs: wm5102: Use guard() for mutex locks

Richard Fitzgerald <[email protected]>
Newsgroups gmane.linux.sound,gmane.linux.kernel,gmane.linux.ports.arm.msm
Message-ID <[email protected]>
On 23/07/2026 5:53 am, [email protected] wrote:
> From: bui duc phuc <[email protected]>
> 
> Clean up the code using guard() for mutex locks.
> Merely code refactoring, and no behavior change.
> 
> Signed-off-by: bui duc phuc <[email protected]>
> ---
>   sound/soc/codecs/wm5102.c | 23 +++++++++--------------
>   1 file changed, 9 insertions(+), 14 deletions(-)
> 
> diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
> index b4d4137c05b4..74b775b95bfd 100644
> --- a/sound/soc/codecs/wm5102.c
> +++ b/sound/soc/codecs/wm5102.c
> @@ -7,6 +7,7 @@
>    * Author: Mark Brown <[email protected]>
>    */
>   
> +#include <linux/cleanup.h>
>   #include <linux/module.h>
>   #include <linux/moduleparam.h>
>   #include <linux/init.h>
> @@ -667,10 +668,9 @@ static int wm5102_out_comp_coeff_get(struct snd_kcontrol *kcontrol,
>   	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
>   	struct arizona *arizona = dev_get_drvdata(component->dev->parent);
>   
> -	mutex_lock(&arizona->dac_comp_lock);
> +	guard(mutex)(&arizona->dac_comp_lock);
>   	put_unaligned_be16(arizona->dac_comp_coeff,
>   			   ucontrol->value.bytes.data);
> -	mutex_unlock(&arizona->dac_comp_lock);
>   
>   	return 0;
>   }
> @@ -681,16 +681,14 @@ static int wm5102_out_comp_coeff_put(struct snd_kcontrol *kcontrol,
>   	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
>   	struct arizona *arizona = dev_get_drvdata(component->dev->parent);
>   	uint16_t dac_comp_coeff = get_unaligned_be16(ucontrol->value.bytes.data);
> -	int ret = 0;
>   
> -	mutex_lock(&arizona->dac_comp_lock);
> +	guard(mutex)(&arizona->dac_comp_lock);
>   	if (arizona->dac_comp_coeff != dac_comp_coeff) {
>   		arizona->dac_comp_coeff = dac_comp_coeff;
> -		ret = 1;
> +		return 1;
>   	}
> -	mutex_unlock(&arizona->dac_comp_lock);
>   
> -	return ret;
> +	return 0;
>   }
>   
>   static int wm5102_out_comp_switch_get(struct snd_kcontrol *kcontrol,
> @@ -699,9 +697,8 @@ static int wm5102_out_comp_switch_get(struct snd_kcontrol *kcontrol,
>   	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
>   	struct arizona *arizona = dev_get_drvdata(component->dev->parent);
>   
> -	mutex_lock(&arizona->dac_comp_lock);
> +	guard(mutex)(&arizona->dac_comp_lock);
>   	ucontrol->value.integer.value[0] = arizona->dac_comp_enabled;
> -	mutex_unlock(&arizona->dac_comp_lock);
>   
>   	return 0;
>   }
> @@ -712,19 +709,17 @@ static int wm5102_out_comp_switch_put(struct snd_kcontrol *kcontrol,
>   	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
>   	struct arizona *arizona = dev_get_drvdata(component->dev->parent);
>   	struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
> -	int ret = 0;
>   
>   	if (ucontrol->value.integer.value[0] > mc->max)
>   		return -EINVAL;
>   
> -	mutex_lock(&arizona->dac_comp_lock);
> +	guard(mutex)(&arizona->dac_comp_lock);
>   	if (arizona->dac_comp_enabled != ucontrol->value.integer.value[0]) {
>   		arizona->dac_comp_enabled = ucontrol->value.integer.value[0];
> -		ret = 1;
> +		return 1;
>   	}
> -	mutex_unlock(&arizona->dac_comp_lock);
>   
> -	return ret;
> +	return 0;
>   }
>   
>   static const char * const wm5102_osr_text[] = {

Reviewed-by: Richard Fitzgerald <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.