All of lore.kernel.org
 help / color / mirror / Atom feed
From: phucduc.bui@gmail.com
To: Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	nuno.sa@analog.com, Shenghao Ding <shenghao-ding@ti.com>,
	Kevin Lu <kevin-lu@ti.com>
Cc: Baojun Xu <baojun.xu@ti.com>, Sen Wang <sen@ti.com>,
	Steven Eckhoff <steven.eckhoff.opensource@gmail.com>,
	Srinivas Kandagatla <srini@kernel.org>,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	Charles Keepax <ckeepax@opensource.cirrus.com>,
	Linus Walleij <linusw@kernel.org>,
	u.kleine-koenig@baylibre.com,
	Thorsten Blum <thorsten.blum@linux.dev>,
	Kees Cook <kees@kernel.org>, Chen Ni <nichen@iscas.ac.cn>,
	Bartosz Golaszewski <brgl@kernel.org>,
	Shengjiu Wang <shengjiu.wang@nxp.com>,
	Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>,
	Pengpeng Hou <pengpeng@iscas.ac.cn>,
	Richard Fitzgerald <rf@opensource.cirrus.com>,
	patches@opensource.cirrus.com, linux-kernel@vger.kernel.org,
	linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH 04/26] ASoC: codecs: tas2781: Use guard() for mutex locks
Date: Thu, 23 Jul 2026 11:53:05 +0700	[thread overview]
Message-ID: <20260723045327.28260-5-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260723045327.28260-1-phucduc.bui@gmail.com>

From: bui duc phuc <phucduc.bui@gmail.com>

Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.

Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
 sound/soc/codecs/tas2781-comlib-i2c.c |  5 ++---
 sound/soc/codecs/tas2781-i2c.c        | 32 +++++++++++----------------
 2 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/sound/soc/codecs/tas2781-comlib-i2c.c b/sound/soc/codecs/tas2781-comlib-i2c.c
index e24d56a14cfd..79b5f5b04c74 100644
--- a/sound/soc/codecs/tas2781-comlib-i2c.c
+++ b/sound/soc/codecs/tas2781-comlib-i2c.c
@@ -6,6 +6,7 @@
 //
 // Author: Shenghao Ding <shenghao-ding@ti.com>
 
+#include <linux/cleanup.h>
 #include <linux/crc8.h>
 #include <linux/firmware.h>
 #include <linux/gpio/consumer.h>
@@ -342,7 +343,7 @@ int tascodec_init(struct tasdevice_priv *tas_priv, void *codec,
 	/* Codec Lock Hold to ensure that codec_probe and firmware parsing and
 	 * loading do not simultaneously execute.
 	 */
-	mutex_lock(&tas_priv->codec_lock);
+	guard(mutex)(&tas_priv->codec_lock);
 
 	if (tas_priv->name_prefix)
 		scnprintf(tas_priv->rca_binaryname, 64, "%s-%sRCA%d.bin",
@@ -360,8 +361,6 @@ int tascodec_init(struct tasdevice_priv *tas_priv, void *codec,
 		dev_err(tas_priv->dev, "request_firmware_nowait err:0x%08x\n",
 			ret);
 
-	/* Codec Lock Release*/
-	mutex_unlock(&tas_priv->codec_lock);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(tascodec_init);
diff --git a/sound/soc/codecs/tas2781-i2c.c b/sound/soc/codecs/tas2781-i2c.c
index 9e6f0ad5f05d..16dd0989e5e2 100644
--- a/sound/soc/codecs/tas2781-i2c.c
+++ b/sound/soc/codecs/tas2781-i2c.c
@@ -13,6 +13,7 @@
 // Author: Kevin Lu <kevin-lu@ti.com>
 //
 
+#include <linux/cleanup.h>
 #include <linux/crc8.h>
 #include <linux/firmware.h>
 #include <linux/gpio/consumer.h>
@@ -843,12 +844,12 @@ static int tasdevice_digital_gain_get(
 	unsigned char data[4];
 	int ret;
 
-	mutex_lock(&tas_dev->codec_lock);
+	guard(mutex)(&tas_dev->codec_lock);
 	/* Read the primary device */
 	ret = tasdevice_dev_bulk_read(tas_dev, 0, reg, data, 4);
 	if (ret) {
 		dev_err(tas_dev->dev, "%s, get AMP vol error\n", __func__);
-		goto out;
+		return ret;
 	}
 
 	target = get_unaligned_be32(&data[0]);
@@ -868,8 +869,7 @@ static int tasdevice_digital_gain_get(
 	/* find out the member same as or closer to the current volume */
 	ucontrol->value.integer.value[0] =
 		abs(target - ar_l) <= abs(target - ar_r) ? l : r;
-out:
-	mutex_unlock(&tas_dev->codec_lock);
+
 	return 0;
 }
 
@@ -882,29 +882,26 @@ static int tasdevice_digital_gain_put(
 	struct snd_soc_component *codec = snd_kcontrol_chip(kcontrol);
 	struct tasdevice_priv *tas_dev = snd_soc_component_get_drvdata(codec);
 	int vol = ucontrol->value.integer.value[0];
-	int status = 0, max = mc->max, rc = 1;
+	int status = 0, max = mc->max;
 	int i, ret;
 	unsigned int reg = mc->reg;
 	unsigned int volrd, volwr;
 	unsigned char data[4];
 
 	vol = clamp(vol, 0, max);
-	mutex_lock(&tas_dev->codec_lock);
+	guard(mutex)(&tas_dev->codec_lock);
 	/* Read the primary device */
 	ret = tasdevice_dev_bulk_read(tas_dev, 0, reg, data, 4);
 	if (ret) {
 		dev_err(tas_dev->dev, "%s, get AMP vol error\n", __func__);
-		rc = -1;
-		goto out;
+		return -1;
 	}
 
 	volrd = get_unaligned_be32(&data[0]);
 	volwr = get_unaligned_be32(tas_dev->dvc_tlv_table[vol]);
 
-	if (volrd == volwr) {
-		rc = 0;
-		goto out;
-	}
+	if (volrd == volwr)
+		return 0;
 
 	for (i = 0; i < tas_dev->ndev; i++) {
 		ret = tasdevice_dev_bulk_write(tas_dev, i, reg,
@@ -918,10 +915,9 @@ static int tasdevice_digital_gain_put(
 	}
 
 	if (status)
-		rc = -1;
-out:
-	mutex_unlock(&tas_dev->codec_lock);
-	return rc;
+		return -1;
+
+	return 1;
 }
 
 static const struct snd_kcontrol_new tasdevice_cali_controls[] = {
@@ -1766,12 +1762,10 @@ static int tasdevice_dapm_event(struct snd_soc_dapm_widget *w,
 	int state = 0;
 
 	/* Codec Lock Hold */
-	mutex_lock(&tas_priv->codec_lock);
+	guard(mutex)(&tas_priv->codec_lock);
 	if (event == SND_SOC_DAPM_PRE_PMD)
 		state = 1;
 	tasdevice_tuning_switch(tas_priv, state);
-	/* Codec Lock Release*/
-	mutex_unlock(&tas_priv->codec_lock);
 
 	return 0;
 }
-- 
2.43.0


  parent reply	other threads:[~2026-07-23  4:54 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23  4:53 [PATCH 00/26] ASoC: codecs: Use guard() for mutex & spin locks - part 3 phucduc.bui
2026-07-23  4:53 ` [PATCH 01/26] ASoC: codecs: sigmadsp: Use guard() for mutex locks phucduc.bui
2026-07-23  4:53 ` [PATCH 02/26] ASoC: codecs: sta350: " phucduc.bui
2026-07-23  4:53 ` [PATCH 03/26] ASoC: codecs: sta32x: " phucduc.bui
2026-07-23  4:53 ` phucduc.bui [this message]
2026-07-23  4:53 ` [PATCH 05/26] ASoC: codecs: tas2783: " phucduc.bui
2026-07-23  4:53 ` [PATCH 06/26] ASoC: codecs: tas5805m: " phucduc.bui
2026-07-23  4:53 ` [PATCH 07/26] ASoC: codecs: tlv320dac33: Use guard() for mutex & spin locks phucduc.bui
2026-07-23  4:53 ` [PATCH 08/26] ASoC: codecs: tscs42xx: Use guard() for mutex locks phucduc.bui
2026-07-23  4:53 ` [PATCH 09/26] ASoC: codecs: tscs454: " phucduc.bui
2026-07-23  4:53 ` [PATCH 10/26] ASoC: codecs: twl6040: " phucduc.bui
2026-07-23  4:53 ` [PATCH 11/26] ASoC: codecs: wcd-mbhc: " phucduc.bui
2026-07-23  4:53 ` [PATCH 12/26] ASoC: codecs: wcd934x: " phucduc.bui
2026-07-23  4:53 ` [PATCH 13/26] ASoC: codecs: wcd937x: " phucduc.bui
2026-07-23  4:53 ` [PATCH 14/26] ASoC: codecs: wcd938x: " phucduc.bui
2026-07-23  4:53 ` [PATCH 15/26] ASoC: codecs: wcd939x: " phucduc.bui
2026-07-23  4:53 ` [PATCH 16/26] ASoC: codecs: wm0010: Use guard() for mutex & spin locks phucduc.bui
2026-07-23  4:53 ` [PATCH 17/26] ASoC: codecs: wm2000: Use guard() for mutex locks phucduc.bui
2026-07-23  4:53 ` [PATCH 18/26] ASoC: codecs: wm5102: " phucduc.bui
2026-07-23  4:53 ` [PATCH 19/26] ASoC: codecs: wm8731: " phucduc.bui
2026-07-23  4:53 ` [PATCH 20/26] ASoC: codecs: wm8903: " phucduc.bui
2026-07-23  4:53 ` [PATCH 21/26] ASoC: codecs: wm8958: " phucduc.bui
2026-07-23  4:53 ` [PATCH 22/26] ASoC: codecs: wm8962: " phucduc.bui
2026-07-23  4:53 ` [PATCH 23/26] ASoC: codecs: wm8994: " phucduc.bui
2026-07-23  4:53 ` [PATCH 24/26] ASoC: codecs: wm971x: " phucduc.bui
2026-07-23  4:53 ` [PATCH 25/26] ASoC: codecs: wm_adsp: " phucduc.bui
2026-07-23  4:53 ` [PATCH 26/26] ASoC: codecs: wsa88xx: " phucduc.bui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260723045327.28260-5-phucduc.bui@gmail.com \
    --to=phucduc.bui@gmail.com \
    --cc=baojun.xu@ti.com \
    --cc=brgl@kernel.org \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=kees@kernel.org \
    --cc=kevin-lu@ti.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=linusw@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=nichen@iscas.ac.cn \
    --cc=nuno.sa@analog.com \
    --cc=patches@opensource.cirrus.com \
    --cc=pengpeng@iscas.ac.cn \
    --cc=perex@perex.cz \
    --cc=rf@opensource.cirrus.com \
    --cc=sebastian.krzyszkowiak@puri.sm \
    --cc=sen@ti.com \
    --cc=shenghao-ding@ti.com \
    --cc=shengjiu.wang@nxp.com \
    --cc=srini@kernel.org \
    --cc=steven.eckhoff.opensource@gmail.com \
    --cc=thorsten.blum@linux.dev \
    --cc=tiwai@suse.com \
    --cc=u.kleine-koenig@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.