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, bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH v2 14/24] ASoC: codecs: cs42l42: Use guard() cleanup helpers
Date: Fri,  3 Jul 2026 12:53:45 +0700	[thread overview]
Message-ID: <20260703055355.244898-15-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260703055355.244898-1-phucduc.bui@gmail.com>

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

Clean up the code using guard() helpers for mutex locking
and PM runtime management.
No functional change intended.

Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
 sound/soc/codecs/cs42l42.c | 54 +++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 30 deletions(-)

diff --git a/sound/soc/codecs/cs42l42.c b/sound/soc/codecs/cs42l42.c
index 2652a639a79a..fadf68860601 100644
--- a/sound/soc/codecs/cs42l42.c
+++ b/sound/soc/codecs/cs42l42.c
@@ -9,6 +9,7 @@
  * Author: Michael White <michael.white@cirrus.com>
  */
 
+#include <linux/cleanup.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/types.h>
@@ -565,7 +566,7 @@ static int cs42l42_set_jack(struct snd_soc_component *component, struct snd_soc_
 	struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(component);
 
 	/* Prevent race with interrupt handler */
-	mutex_lock(&cs42l42->irq_lock);
+	guard(mutex)(&cs42l42->irq_lock);
 	cs42l42->jack = jk;
 
 	if (jk) {
@@ -581,7 +582,6 @@ static int cs42l42_set_jack(struct snd_soc_component *component, struct snd_soc_
 			break;
 		}
 	}
-	mutex_unlock(&cs42l42->irq_lock);
 
 	return 0;
 }
@@ -1668,13 +1668,10 @@ irqreturn_t cs42l42_irq_thread(int irq, void *data)
 	unsigned int current_button_status;
 	unsigned int i;
 
-	pm_runtime_get_sync(cs42l42->dev);
-	mutex_lock(&cs42l42->irq_lock);
-	if (cs42l42->suspended || !cs42l42->init_done) {
-		mutex_unlock(&cs42l42->irq_lock);
-		pm_runtime_put_autosuspend(cs42l42->dev);
+	guard(pm_runtime_active_auto)(cs42l42->dev);
+	guard(mutex)(&cs42l42->irq_lock);
+	if (cs42l42->suspended || !cs42l42->init_done)
 		return IRQ_NONE;
-	}
 
 	/* Read sticky registers to clear interurpt */
 	for (i = 0; i < ARRAY_SIZE(stickies); i++) {
@@ -1774,9 +1771,6 @@ irqreturn_t cs42l42_irq_thread(int irq, void *data)
 		}
 	}
 
-	mutex_unlock(&cs42l42->irq_lock);
-	pm_runtime_put_autosuspend(cs42l42->dev);
-
 	return IRQ_HANDLED;
 }
 EXPORT_SYMBOL_NS_GPL(cs42l42_irq_thread, "SND_SOC_CS42L42_CORE");
@@ -2163,22 +2157,22 @@ int cs42l42_suspend(struct device *dev)
 	 * future interrupts. This ensures a safe disable if the interrupt
 	 * is shared.
 	 */
-	mutex_lock(&cs42l42->irq_lock);
-	cs42l42->suspended = true;
+	scoped_guard(mutex, &cs42l42->irq_lock) {
+		cs42l42->suspended = true;
 
-	/* Save register values that will be overwritten by shutdown sequence */
-	for (i = 0; i < ARRAY_SIZE(cs42l42_shutdown_seq); ++i) {
-		regmap_read(cs42l42->regmap, cs42l42_shutdown_seq[i].reg, &reg);
-		save_regs[i] = (u8)reg;
-	}
+		/* Save register values that will be overwritten by shutdown sequence */
+		for (i = 0; i < ARRAY_SIZE(cs42l42_shutdown_seq); ++i) {
+			regmap_read(cs42l42->regmap, cs42l42_shutdown_seq[i].reg, &reg);
+			save_regs[i] = (u8)reg;
+		}
 
-	/* Shutdown codec */
-	regmap_multi_reg_write(cs42l42->regmap,
-			       cs42l42_shutdown_seq,
-			       ARRAY_SIZE(cs42l42_shutdown_seq));
+		/* Shutdown codec */
+		regmap_multi_reg_write(cs42l42->regmap,
+				       cs42l42_shutdown_seq,
+				       ARRAY_SIZE(cs42l42_shutdown_seq));
 
-	/* All interrupt sources are now disabled */
-	mutex_unlock(&cs42l42->irq_lock);
+		/* All interrupt sources are now disabled */
+	}
 
 	/* Wait for power-down complete */
 	msleep(CS42L42_PDN_DONE_TIME_MS);
@@ -2250,13 +2244,13 @@ void cs42l42_resume_restore(struct device *dev)
 	regcache_cache_only(cs42l42->regmap, false);
 	regcache_mark_dirty(cs42l42->regmap);
 
-	mutex_lock(&cs42l42->irq_lock);
-	/* Sync LATCH_TO_VP first so the VP domain registers sync correctly */
-	regcache_sync_region(cs42l42->regmap, CS42L42_MIC_DET_CTL1, CS42L42_MIC_DET_CTL1);
-	regcache_sync(cs42l42->regmap);
+	scoped_guard(mutex, &cs42l42->irq_lock) {
+		/* Sync LATCH_TO_VP first so the VP domain registers sync correctly */
+		regcache_sync_region(cs42l42->regmap, CS42L42_MIC_DET_CTL1, CS42L42_MIC_DET_CTL1);
+		regcache_sync(cs42l42->regmap);
 
-	cs42l42->suspended = false;
-	mutex_unlock(&cs42l42->irq_lock);
+		cs42l42->suspended = false;
+	}
 
 	dev_dbg(dev, "System resumed\n");
 }
-- 
2.43.0


  parent reply	other threads:[~2026-07-03  5:56 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03  5:53 [PATCH v2 00/24] ASoC: codecs: Use guard() for mutex & spin lock - part 1 phucduc.bui
2026-07-03  5:53 ` [PATCH v2 01/24] ASoC: codecs: ab8500: Use guard() for mutex locks phucduc.bui
2026-07-03  5:53 ` [PATCH v2 02/24] ASoC: codecs: ak4613: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 03/24] ASoC: codecs: arizona-jack: Use guard() cleanup helpers phucduc.bui
2026-07-06 12:58   ` Charles Keepax
2026-07-07  2:29     ` Bui Duc Phuc
2026-07-03  5:53 ` [PATCH v2 04/24] ASoC: codecs: arizona: Use guard() for mutex locks phucduc.bui
2026-07-03  5:53 ` [PATCH v2 05/24] ASoC: codecs: aw87390: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 06/24] ASoC: codecs: aw88081: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 07/24] ASoC: codecs: aw88166: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 08/24] ASoC: codecs: aw88261: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 09/24] ASoC: codecs: aw88395: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 10/24] ASoC: codecs: aw88399: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 11/24] ASoC: codecs: cros_ec_codec: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 12/24] ASoC: codecs: cs-amp-lib: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 13/24] ASoC: codecs: cs35l56: Use guard() and PM runtime scope helpers phucduc.bui
2026-07-06  9:38   ` Richard Fitzgerald
2026-07-06 10:12   ` Cezary Rojewski
2026-07-06 10:46     ` Bui Duc Phuc
2026-07-06 10:58       ` Richard Fitzgerald
2026-07-06 12:37         ` Bui Duc Phuc
2026-07-03  5:53 ` phucduc.bui [this message]
2026-07-03  5:53 ` [PATCH v2 15/24] ASoC: codecs: cs42l43: " phucduc.bui
2026-07-06 13:18   ` Charles Keepax
2026-07-07  3:59     ` Bui Duc Phuc
2026-07-03  5:53 ` [PATCH v2 16/24] ASoC: codecs: cs42l84: Use guard() for mutex locks phucduc.bui
2026-07-03  5:53 ` [PATCH v2 17/24] ASoC: codecs: cs43130: " phucduc.bui
2026-07-06 13:20   ` Charles Keepax
2026-07-03  5:53 ` [PATCH v2 18/24] ASoC: codecs: cs47l15: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 19/24] ASoC: codecs: cs47l35: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 20/24] ASoC: codecs: cs47l85: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 21/24] ASoC: codecs: cs47l90: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 22/24] ASoC: codecs: cs47l92: " phucduc.bui
2026-07-03  5:53 ` [PATCH v2 23/24] ASoC: codecs: cs48l32: " phucduc.bui
2026-07-06 13:23   ` Charles Keepax
2026-07-03  5:53 ` [PATCH v2 24/24] ASoC: codecs: cs2072x: " phucduc.bui
2026-07-06 10:21 ` [PATCH v2 00/24] ASoC: codecs: Use guard() for mutex & spin lock - part 1 Cezary Rojewski
2026-07-07  4:40   ` Bui Duc Phuc

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=20260703055355.244898-15-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=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.