[PATCH 19/27] ASoC: codecs: rt5665: Use guard() for mutex locks

From: phucduc . bui

Date: Tue Jun 30 2026 - 02:48:05 EST


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/rt5665.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/rt5665.c b/sound/soc/codecs/rt5665.c
index 48f57cd0920d..1d987472ba42 100644
--- a/sound/soc/codecs/rt5665.c
+++ b/sound/soc/codecs/rt5665.c
@@ -6,6 +6,7 @@
* Author: Bard Liao <bardliao@xxxxxxxxxxx>
*/

+#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
@@ -1208,7 +1209,7 @@ static void rt5665_jack_detect_handler(struct work_struct *work)
usleep_range(10000, 15000);
}

- mutex_lock(&rt5665->calibrate_mutex);
+ guard(mutex)(&rt5665->calibrate_mutex);

val = snd_soc_component_read(rt5665->component, RT5665_AJD1_CTRL) & 0x0010;
if (!val) {
@@ -1274,8 +1275,6 @@ static void rt5665_jack_detect_handler(struct work_struct *work)
schedule_delayed_work(&rt5665->jd_check_work, 0);
else
cancel_delayed_work_sync(&rt5665->jd_check_work);
-
- mutex_unlock(&rt5665->calibrate_mutex);
}

static const char * const rt5665_clk_sync[] = {
@@ -4564,7 +4563,7 @@ static void rt5665_calibrate(struct rt5665_priv *rt5665)
{
int value, count;

- mutex_lock(&rt5665->calibrate_mutex);
+ guard(mutex)(&rt5665->calibrate_mutex);

regcache_cache_bypass(rt5665->regmap, true);

@@ -4601,7 +4600,8 @@ static void rt5665_calibrate(struct rt5665_priv *rt5665)
pr_err("HP Calibration Failure\n");
regmap_write(rt5665->regmap, RT5665_RESET, 0);
regcache_cache_bypass(rt5665->regmap, false);
- goto out_unlock;
+ rt5665->calibration_done = true;
+ return;
}

count++;
@@ -4620,7 +4620,8 @@ static void rt5665_calibrate(struct rt5665_priv *rt5665)
pr_err("MONO Calibration Failure\n");
regmap_write(rt5665->regmap, RT5665_RESET, 0);
regcache_cache_bypass(rt5665->regmap, false);
- goto out_unlock;
+ rt5665->calibration_done = true;
+ return;
}

count++;
@@ -4635,9 +4636,7 @@ static void rt5665_calibrate(struct rt5665_priv *rt5665)
regmap_write(rt5665->regmap, RT5665_BIAS_CUR_CTRL_8, 0xa602);
regmap_write(rt5665->regmap, RT5665_ASRC_8, 0x0120);

-out_unlock:
rt5665->calibration_done = true;
- mutex_unlock(&rt5665->calibrate_mutex);
}

static void rt5665_calibrate_handler(struct work_struct *work)
--
2.43.0