Re: [PATCH 22/26] ASoC: codecs: wm8962: Use guard() for mutex locks
From: Richard Fitzgerald
Date: Thu Jul 23 2026 - 06:13:10 EST
On 23/07/2026 5:53 am, phucduc.bui@xxxxxxxxx wrote:
From: bui duc phuc <phucduc.bui@xxxxxxxxx>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
Signed-off-by: bui duc phuc <phucduc.bui@xxxxxxxxx>
---
sound/soc/codecs/wm8962.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index 2db822fc1de7..8a9598161b35 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/pm.h>
@@ -1564,11 +1565,10 @@ static int wm8962_dsp2_ena_put(struct snd_kcontrol *kcontrol,
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
struct wm8962_priv *wm8962 = snd_soc_component_get_drvdata(component);
int old = wm8962->dsp2_ena;
- int ret = 0;
int dsp2_running = snd_soc_component_read(component, WM8962_DSP2_POWER_MANAGEMENT) &
WM8962_DSP2_ENA;
- mutex_lock(&wm8962->dsp2_ena_lock);
+ guard(mutex)(&wm8962->dsp2_ena_lock);
if (ucontrol->value.integer.value[0])
wm8962->dsp2_ena |= 1 << shift;
@@ -1576,9 +1576,7 @@ static int wm8962_dsp2_ena_put(struct snd_kcontrol *kcontrol,
wm8962->dsp2_ena &= ~(1 << shift);
if (wm8962->dsp2_ena == old)
- goto out;
-
- ret = 1;
+ return 0;
if (dsp2_running) {
if (wm8962->dsp2_ena)
@@ -1587,10 +1585,7 @@ static int wm8962_dsp2_ena_put(struct snd_kcontrol *kcontrol,
wm8962_dsp2_stop(component);
}
-out:
- mutex_unlock(&wm8962->dsp2_ena_lock);
-
- return ret;
+ return 1;
}
/* The VU bits for the headphones are in a different register to the mute
Reviewed-by: Richard Fitzgerald <rf@xxxxxxxxxxxxxxxxxxxxx>