All of lore.kernel.org
 help / color / mirror / Atom feed
From: phucduc.bui@gmail.com
To: Mark Brown <broonie@kernel.org>, Takashi Iwai <tiwai@suse.com>,
	Tzung-Bi Shih <tzungbi@kernel.org>,
	David Rhodes <david.rhodes@cirrus.com>,
	Charles Keepax <ckeepax@opensource.cirrus.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>,
	Cheng-Yi Chiang <cychiang@chromium.org>,
	Guenter Roeck <groeck@chromium.org>,
	Benson Leung <bleung@chromium.org>,
	Richard Fitzgerald <rf@opensource.cirrus.com>,
	povik+lin@cutebit.org, u.kleine-koenig@baylibre.com,
	kuninori.morimoto.gx@renesas.com, christian.ehrhardt@codasip.com,
	Linus Walleij <linusw@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Thorsten Blum <thorsten.blum@linux.dev>,
	Chris Morgan <macromorgan@hotmail.com>,
	Dan Carpenter <error27@gmail.com>,
	Marco Crivellari <marco.crivellari@suse.com>,
	Rosen Penev <rosenp@gmail.com>,
	Weidong Wang <wangweidong.a@awinic.com>,
	Teguh Sobirin <teguh@sobir.in>, Val Packett <val@packett.cool>,
	Luca Weiss <luca.weiss@fairphone.com>,
	wangdicheng <wangdicheng@kylinos.cn>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@opensource.cirrus.com, chrome-platform@lists.linux.dev,
	asahi@lists.linux.dev,
	Cezary Rojewski <cezary.rojewski@intel.com>,
	bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH v4 02/24] ASoC: codecs: ak4613: Use guard() for mutex locks
Date: Wed,  8 Jul 2026 19:49:39 +0700	[thread overview]
Message-ID: <20260708125002.202515-3-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260708125002.202515-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.

Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
 sound/soc/codecs/ak4613.c | 83 +++++++++++++++++++--------------------
 1 file changed, 40 insertions(+), 43 deletions(-)

diff --git a/sound/soc/codecs/ak4613.c b/sound/soc/codecs/ak4613.c
index 3e0696b5abf5..be5306d07d40 100644
--- a/sound/soc/codecs/ak4613.c
+++ b/sound/soc/codecs/ak4613.c
@@ -95,6 +95,7 @@
  * see
  *	AK4613_ENABLE_TDM_TEST
  */
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/i2c.h>
@@ -384,7 +385,7 @@ static void ak4613_dai_shutdown(struct snd_pcm_substream *substream,
 	struct ak4613_priv *priv = snd_soc_component_get_drvdata(component);
 	struct device *dev = component->dev;
 
-	mutex_lock(&priv->lock);
+	guard(mutex)(&priv->lock);
 	priv->cnt--;
 	if (priv->cnt < 0) {
 		dev_err(dev, "unexpected counter error\n");
@@ -392,7 +393,6 @@ static void ak4613_dai_shutdown(struct snd_pcm_substream *substream,
 	}
 	if (!priv->cnt)
 		priv->ctrl1 = 0;
-	mutex_unlock(&priv->lock);
 }
 
 static void ak4613_hw_constraints(struct ak4613_priv *priv,
@@ -507,10 +507,9 @@ static int ak4613_dai_startup(struct snd_pcm_substream *substream,
 	struct snd_soc_component *component = dai->component;
 	struct ak4613_priv *priv = snd_soc_component_get_drvdata(component);
 
-	mutex_lock(&priv->lock);
+	guard(mutex)(&priv->lock);
 	ak4613_hw_constraints(priv, substream);
 	priv->cnt++;
-	mutex_unlock(&priv->lock);
 
 	return 0;
 }
@@ -599,45 +598,47 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,
 	 */
 	ret = -EINVAL;
 
-	mutex_lock(&priv->lock);
-	if (priv->cnt > 1) {
-		/*
-		 * If it was already working, use current priv->ctrl1
-		 */
-		ret = 0;
-	} else {
-		/*
-		 * It is not yet working,
-		 */
-		unsigned int channel = params_channels(params);
-		u8 tdm;
-
-		/* STEREO or TDM */
-		if (channel == 2)
-			tdm = AK4613_CONFIG_MODE_STEREO;
-		else
-			tdm = AK4613_CONFIG_GET(priv, MODE);
-
-		for (i = ARRAY_SIZE(ak4613_iface) - 1; i >= 0; i--) {
-			const struct ak4613_interface *iface = ak4613_iface + i;
-
-			if ((iface->fmt == fmt) && (iface->width == width)) {
-				/*
-				 * Ctrl1
-				 * | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0  |
-				 * |TDM1|TDM0|DIF2|DIF1|DIF0|ATS1|ATS0|SMUTE|
-				 *  <  tdm  > < iface->dif >
-				 */
-				priv->ctrl1 = (tdm << 6) | (iface->dif << 3);
-				ret = 0;
-				break;
+	scoped_guard(mutex, &priv->lock) {
+		if (priv->cnt > 1) {
+			/*
+			 * If it was already working, use current priv->ctrl1
+			 */
+			ret = 0;
+		} else {
+			/*
+			 * It is not yet working,
+			 */
+			unsigned int channel = params_channels(params);
+			u8 tdm;
+
+			/* STEREO or TDM */
+			if (channel == 2)
+				tdm = AK4613_CONFIG_MODE_STEREO;
+			else
+				tdm = AK4613_CONFIG_GET(priv, MODE);
+
+			for (i = ARRAY_SIZE(ak4613_iface) - 1; i >= 0; i--) {
+				const struct ak4613_interface *iface = ak4613_iface + i;
+
+				if (iface->fmt == fmt && iface->width == width) {
+					/*
+					 * Ctrl1
+					 * | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0  |
+					 * |TDM1|TDM0|DIF2|DIF1|DIF0|ATS1|ATS0|SMUTE|
+					 *  <  tdm  > < iface->dif >
+					 */
+					priv->ctrl1 = (tdm << 6) | (iface->dif << 3);
+					ret = 0;
+					break;
+				}
 			}
 		}
 	}
-	mutex_unlock(&priv->lock);
 
-	if (ret < 0)
-		goto hw_params_end;
+	if (ret < 0) {
+		dev_warn(dev, "unsupported data width/format combination\n");
+		return ret;
+	}
 
 	snd_soc_component_update_bits(component, CTRL1, FMT_MASK, priv->ctrl1);
 	snd_soc_component_update_bits(component, CTRL2, DFS_MASK, ctrl2);
@@ -645,10 +646,6 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,
 	snd_soc_component_update_bits(component, ICTRL, ICTRL_MASK, priv->ic);
 	snd_soc_component_update_bits(component, OCTRL, OCTRL_MASK, priv->oc);
 
-hw_params_end:
-	if (ret < 0)
-		dev_warn(dev, "unsupported data width/format combination\n");
-
 	return ret;
 }
 
-- 
2.43.0


  parent reply	other threads:[~2026-07-08 12:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08 12:49 [PATCH v4 00/24] ASoC: codecs: Use guard() for mutex & spin lock - part 1 phucduc.bui
2026-07-08 12:49 ` [PATCH v4 01/24] ASoC: codecs: ab8500: Use guard() for mutex locks phucduc.bui
2026-07-09 16:56   ` Linus Walleij
2026-07-08 12:49 ` phucduc.bui [this message]
2026-07-08 12:49 ` [PATCH v4 03/24] ASoC: codecs: arizona-jack: Use guard() cleanup helpers phucduc.bui
2026-07-08 12:49 ` [PATCH v4 04/24] ASoC: codecs: arizona: Use guard() for mutex locks phucduc.bui
2026-07-08 12:49 ` [PATCH v4 05/24] ASoC: codecs: aw87390: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 06/24] ASoC: codecs: aw88081: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 07/24] ASoC: codecs: aw88166: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 08/24] ASoC: codecs: aw88261: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 09/24] ASoC: codecs: aw88395: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 10/24] ASoC: codecs: aw88399: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 11/24] ASoC: codecs: cros_ec_codec: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 12/24] ASoC: codecs: cs-amp-lib: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 13/24] ASoC: codecs: cs35l56: Use guard() and PM runtime scope helpers phucduc.bui
2026-07-08 12:49 ` [PATCH v4 14/24] ASoC: codecs: cs42l42: Use guard() cleanup helpers phucduc.bui
2026-07-08 12:49 ` [PATCH v4 15/24] ASoC: codecs: cs42l43: Use guard() and PM runtime scope helpers phucduc.bui
2026-07-08 12:49 ` [PATCH v4 16/24] ASoC: codecs: cs42l84: Use guard() for mutex locks phucduc.bui
2026-07-08 12:49 ` [PATCH v4 17/24] ASoC: codecs: cs43130: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 18/24] ASoC: codecs: cs47l15: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 19/24] ASoC: codecs: cs47l35: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 20/24] ASoC: codecs: cs47l85: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 21/24] ASoC: codecs: cs47l90: " phucduc.bui
2026-07-08 12:49 ` [PATCH v4 22/24] ASoC: codecs: cs47l92: " phucduc.bui
2026-07-08 12:50 ` [PATCH v4 23/24] ASoC: codecs: cs48l32: " phucduc.bui
2026-07-08 12:50 ` [PATCH v4 24/24] ASoC: codecs: cx2072x: " 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=20260708125002.202515-3-phucduc.bui@gmail.com \
    --to=phucduc.bui@gmail.com \
    --cc=arnd@arndb.de \
    --cc=asahi@lists.linux.dev \
    --cc=bleung@chromium.org \
    --cc=broonie@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --cc=christian.ehrhardt@codasip.com \
    --cc=chrome-platform@lists.linux.dev \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=cychiang@chromium.org \
    --cc=david.rhodes@cirrus.com \
    --cc=error27@gmail.com \
    --cc=groeck@chromium.org \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lgirdwood@gmail.com \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=luca.weiss@fairphone.com \
    --cc=macromorgan@hotmail.com \
    --cc=marco.crivellari@suse.com \
    --cc=patches@opensource.cirrus.com \
    --cc=perex@perex.cz \
    --cc=povik+lin@cutebit.org \
    --cc=rf@opensource.cirrus.com \
    --cc=rosenp@gmail.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=teguh@sobir.in \
    --cc=thorsten.blum@linux.dev \
    --cc=tiwai@suse.com \
    --cc=tzungbi@kernel.org \
    --cc=u.kleine-koenig@baylibre.com \
    --cc=val@packett.cool \
    --cc=wangdicheng@kylinos.cn \
    --cc=wangweidong.a@awinic.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.