Re: [PATCH 17/26] ASoC: codecs: wm2000: Use guard() for mutex locks
Richard Fitzgerald <[email protected]>
| Newsgroups | org.kernel.vger.linux-sound,org.kernel.vger.linux-arm-msm,org.kernel.vger.linux-kernel |
|---|---|
| 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/wm2000.c | 28 +++++++--------------------- > 1 file changed, 7 insertions(+), 21 deletions(-) > > diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c > index 9b68ee69324b..897b0acac5f3 100644 > --- a/sound/soc/codecs/wm2000.c > +++ b/sound/soc/codecs/wm2000.c > @@ -23,6 +23,7 @@ > #include <linux/kernel.h> > #include <linux/init.h> > #include <linux/firmware.h> > +#include <linux/cleanup.h> > #include <linux/clk.h> > #include <linux/delay.h> > #include <linux/pm.h> > @@ -612,20 +613,15 @@ static int wm2000_anc_mode_put(struct snd_kcontrol *kcontrol, > struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); > struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev); > unsigned int anc_active = ucontrol->value.integer.value[0]; > - int ret; > > if (anc_active > 1) > return -EINVAL; > > - mutex_lock(&wm2000->lock); > + guard(mutex)(&wm2000->lock); > > wm2000->anc_active = anc_active; > > - ret = wm2000_anc_set_mode(wm2000); > - > - mutex_unlock(&wm2000->lock); > - > - return ret; > + return wm2000_anc_set_mode(wm2000); > } > > static int wm2000_speaker_get(struct snd_kcontrol *kcontrol, > @@ -645,20 +641,15 @@ static int wm2000_speaker_put(struct snd_kcontrol *kcontrol, > struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); > struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev); > unsigned int val = ucontrol->value.integer.value[0]; > - int ret; > > if (val > 1) > return -EINVAL; > > - mutex_lock(&wm2000->lock); > + guard(mutex)(&wm2000->lock); > > wm2000->spk_ena = val; > > - ret = wm2000_anc_set_mode(wm2000); > - > - mutex_unlock(&wm2000->lock); > - > - return ret; > + return wm2000_anc_set_mode(wm2000); > } > > static const struct snd_kcontrol_new wm2000_controls[] = { > @@ -676,9 +667,8 @@ static int wm2000_anc_power_event(struct snd_soc_dapm_widget *w, > { > struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); > struct wm2000_priv *wm2000 = dev_get_drvdata(component->dev); > - int ret; > > - mutex_lock(&wm2000->lock); > + guard(mutex)(&wm2000->lock); > > if (SND_SOC_DAPM_EVENT_ON(event)) > wm2000->anc_eng_ena = 1; > @@ -686,11 +676,7 @@ static int wm2000_anc_power_event(struct snd_soc_dapm_widget *w, > if (SND_SOC_DAPM_EVENT_OFF(event)) > wm2000->anc_eng_ena = 0; > > - ret = wm2000_anc_set_mode(wm2000); > - > - mutex_unlock(&wm2000->lock); > - > - return ret; > + return wm2000_anc_set_mode(wm2000); > } > > static const struct snd_soc_dapm_widget wm2000_dapm_widgets[] = { Reviewed-by: Richard Fitzgerald <[email protected]>