[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20241209-cleanup-h-guard-of-node-asoc-v1-3-397f6385e4a5@linaro.org>
Date: Mon, 09 Dec 2024 13:00:30 +0100
From: Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>
To: Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
Jaroslav Kysela <perex@...ex.cz>, Takashi Iwai <tiwai@...e.com>
Cc: linux-sound@...r.kernel.org, linux-kernel@...r.kernel.org,
Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>
Subject: [PATCH RESEND 3/3] ASoC: codecs: wcd939x: Simplify locking with
guard()
Simplify error handling with guard(mutex), which allows to drop local
'ret' variable and to directly return instead of jumping.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>
---
sound/soc/codecs/wcd939x.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/sound/soc/codecs/wcd939x.c b/sound/soc/codecs/wcd939x.c
index 4a417a92514d7979aab8a7b67c518e9889e12012..e033e153c2e8e663a04957779625b04ac11c7625 100644
--- a/sound/soc/codecs/wcd939x.c
+++ b/sound/soc/codecs/wcd939x.c
@@ -5,6 +5,7 @@
* Copyright (c) 2023, Linaro Limited
*/
+#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
@@ -1933,7 +1934,6 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
unsigned int micb_reg, cur_vout_ctl, micb_en;
int req_vout_ctl;
- int ret = 0;
switch (micb_num) {
case MIC_BIAS_1:
@@ -1951,7 +1951,8 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
default:
return -EINVAL;
}
- mutex_lock(&wcd939x->micb_lock);
+
+ guard(mutex)(&wcd939x->micb_lock);
/*
* If requested micbias voltage is same as current micbias
@@ -1967,15 +1968,11 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
WCD939X_MICB_VOUT_CTL);
req_vout_ctl = wcd939x_get_micb_vout_ctl_val(req_volt);
- if (req_vout_ctl < 0) {
- ret = req_vout_ctl;
- goto exit;
- }
+ if (req_vout_ctl < 0)
+ return req_vout_ctl;
- if (cur_vout_ctl == req_vout_ctl) {
- ret = 0;
- goto exit;
- }
+ if (cur_vout_ctl == req_vout_ctl)
+ return 0;
dev_dbg(component->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
__func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl),
@@ -2000,9 +1997,7 @@ static int wcd939x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
usleep_range(2000, 2100);
}
-exit:
- mutex_unlock(&wcd939x->micb_lock);
- return ret;
+ return 0;
}
static int wcd939x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component,
--
2.43.0
Powered by blists - more mailing lists