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, 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 03/24] ASoC: codecs: arizona-jack: Use guard() cleanup helpers
Date: Fri, 26 Jun 2026 13:13:08 +0700	[thread overview]
Message-ID: <20260626061329.23264-4-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260626061329.23264-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.

Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
 sound/soc/codecs/arizona-jack.c | 39 +++++++++++++++------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/sound/soc/codecs/arizona-jack.c b/sound/soc/codecs/arizona-jack.c
index a9063bac2752..b0af32e0ddc8 100644
--- a/sound/soc/codecs/arizona-jack.c
+++ b/sound/soc/codecs/arizona-jack.c
@@ -5,6 +5,7 @@
  *  Copyright (C) 2012-2014 Wolfson Microelectronics plc
  */
 
+#include <linux/cleanup.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/slab.h>
@@ -707,15 +708,13 @@ static void arizona_micd_timeout_work(struct work_struct *work)
 						struct arizona_priv,
 						micd_timeout_work.work);
 
-	mutex_lock(&info->lock);
+	guard(mutex)(&info->lock);
 
 	dev_dbg(info->arizona->dev, "MICD timed out, reporting HP\n");
 
 	info->detecting = false;
 
 	arizona_identify_headphone(info);
-
-	mutex_unlock(&info->lock);
 }
 
 static int arizona_micd_adc_read(struct arizona_priv *info)
@@ -921,12 +920,11 @@ static void arizona_micd_detect(struct work_struct *work)
 
 	cancel_delayed_work_sync(&info->micd_timeout_work);
 
-	mutex_lock(&info->lock);
+	guard(mutex)(&info->lock);
 
 	/* If the cable was removed while measuring ignore the result */
 	if (!(info->jack->status & SND_JACK_MECHANICAL)) {
 		dev_dbg(arizona->dev, "Ignoring MICDET for removed cable\n");
-		mutex_unlock(&info->lock);
 		return;
 	}
 
@@ -936,7 +934,6 @@ static void arizona_micd_detect(struct work_struct *work)
 		arizona_button_reading(info);
 
 	pm_runtime_mark_last_busy(arizona->dev);
-	mutex_unlock(&info->lock);
 }
 
 static irqreturn_t arizona_micdet(int irq, void *data)
@@ -948,10 +945,10 @@ static irqreturn_t arizona_micdet(int irq, void *data)
 	cancel_delayed_work_sync(&info->micd_detect_work);
 	cancel_delayed_work_sync(&info->micd_timeout_work);
 
-	mutex_lock(&info->lock);
-	if (!info->detecting)
-		debounce = 0;
-	mutex_unlock(&info->lock);
+	scoped_guard(mutex, &info->lock) {
+		if (!info->detecting)
+			debounce = 0;
+	}
 
 	if (debounce)
 		queue_delayed_work(system_power_efficient_wq,
@@ -969,9 +966,8 @@ static void arizona_hpdet_work(struct work_struct *work)
 						struct arizona_priv,
 						hpdet_work.work);
 
-	mutex_lock(&info->lock);
+	guard(mutex)(&info->lock);
 	arizona_start_hpdet_acc_id(info);
-	mutex_unlock(&info->lock);
 }
 
 static int arizona_hpdet_wait(struct arizona_priv *info)
@@ -1018,9 +1014,9 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
 	cancelled_hp = cancel_delayed_work_sync(&info->hpdet_work);
 	cancelled_mic = cancel_delayed_work_sync(&info->micd_timeout_work);
 
-	pm_runtime_get_sync(arizona->dev);
+	guard(pm_runtime_active_auto)(arizona->dev);
 
-	mutex_lock(&info->lock);
+	guard(mutex)(&info->lock);
 
 	if (info->micd_clamp) {
 		mask = ARIZONA_MICD_CLAMP_STS;
@@ -1036,8 +1032,6 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
 	ret = regmap_read(arizona->regmap, ARIZONA_AOD_IRQ_RAW_STATUS, &val);
 	if (ret) {
 		dev_err(arizona->dev, "Failed to read jackdet status: %d\n", ret);
-		mutex_unlock(&info->lock);
-		pm_runtime_put_autosuspend(arizona->dev);
 		return IRQ_NONE;
 	}
 
@@ -1057,7 +1051,14 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
 					   msecs_to_jiffies(micd_timeout));
 		}
 
-		goto out;
+		/* Clear trig_sts to make sure DCVDD is not forced up */
+		regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG,
+			     ARIZONA_MICD_CLAMP_FALL_TRIG_STS |
+			     ARIZONA_MICD_CLAMP_RISE_TRIG_STS |
+			     ARIZONA_JD1_FALL_TRIG_STS |
+			     ARIZONA_JD1_RISE_TRIG_STS);
+
+		return IRQ_HANDLED;
 	}
 	info->last_jackdet = val;
 
@@ -1111,7 +1112,6 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
 				   ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB);
 	}
 
-out:
 	/* Clear trig_sts to make sure DCVDD is not forced up */
 	regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG,
 		     ARIZONA_MICD_CLAMP_FALL_TRIG_STS |
@@ -1119,9 +1119,6 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
 		     ARIZONA_JD1_FALL_TRIG_STS |
 		     ARIZONA_JD1_RISE_TRIG_STS);
 
-	mutex_unlock(&info->lock);
-
-	pm_runtime_put_autosuspend(arizona->dev);
 
 	return IRQ_HANDLED;
 }
-- 
2.43.0


  parent reply	other threads:[~2026-06-26  6:14 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26  6:13 [PATCH 00/24] ASoC: codecs: Use guard() for mutex & spin locks phucduc.bui
2026-06-26  6:13 ` [PATCH 01/24] ASoC: codecs: ab8500: Use guard() for mutex locks phucduc.bui
2026-06-26  6:13 ` [PATCH 02/24] ASoC: codecs: ak4613: " phucduc.bui
2026-06-26  6:13 ` phucduc.bui [this message]
2026-06-26 12:06   ` [PATCH 03/24] ASoC: codecs: arizona-jack: Use guard() cleanup helpers Charles Keepax
2026-06-26  6:13 ` [PATCH 04/24] ASoC: codecs: arizona: Use guard() for mutex locks phucduc.bui
2026-06-26 10:40   ` Charles Keepax
2026-06-26  6:13 ` [PATCH 05/24] ASoC: codecs: aw87390: " phucduc.bui
2026-06-26  6:13 ` [PATCH 06/24] ASoC: codecs: aw88081: " phucduc.bui
2026-06-26  6:13 ` [PATCH 07/24] ASoC: codecs: aw88166: " phucduc.bui
2026-06-26  6:13 ` [PATCH 08/24] ASoC: codecs: aw88261: " phucduc.bui
2026-06-26  6:13 ` [PATCH 09/24] ASoC: codecs: aw88395: " phucduc.bui
2026-06-26  6:13 ` [PATCH 10/24] ASoC: codecs: aw88399: " phucduc.bui
2026-06-26  6:13 ` [PATCH 11/24] ASoC: codecs: cros_ec_codec: " phucduc.bui
2026-06-26  6:13 ` [PATCH 12/24] ASoC: codecs: cs-amp-lib: " phucduc.bui
2026-06-26  8:47   ` Richard Fitzgerald
2026-06-26  9:36     ` Bui Duc Phuc
2026-06-26  6:13 ` [PATCH 13/24] ASoC: codecs: cs35l56: Use guard() and PM runtime scope helpers phucduc.bui
2026-06-26  6:13 ` [PATCH 14/24] ASoC: codecs: cs42l42: Use guard() cleanup helpers phucduc.bui
2026-06-26 12:18   ` Charles Keepax
2026-06-26  6:13 ` [PATCH 15/24] ASoC: codecs: cs42l43: Use guard() and PM runtime scope helpers phucduc.bui
2026-06-26 10:56   ` Charles Keepax
2026-06-26 12:57     ` Bui Duc Phuc
2026-06-26  6:13 ` [PATCH 16/24] ASoC: codecs: cs42l84: Use guard() for mutex locks phucduc.bui
2026-06-26 10:58   ` Charles Keepax
2026-06-26  6:13 ` [PATCH 17/24] ASoC: codecs: cs43130: " phucduc.bui
2026-06-26  6:13 ` [PATCH 18/24] ASoC: codecs: cs47l15: " phucduc.bui
2026-06-26 12:02   ` Charles Keepax
2026-06-26  6:13 ` [PATCH 19/24] ASoC: codecs: cs47l35: " phucduc.bui
2026-06-26 12:03   ` Charles Keepax
2026-06-26  6:13 ` [PATCH 20/24] ASoC: codecs: cs47l85: " phucduc.bui
2026-06-26 12:03   ` Charles Keepax
2026-06-26  6:13 ` [PATCH 21/24] ASoC: codecs: cs47l90: " phucduc.bui
2026-06-26 12:03   ` Charles Keepax
2026-06-26  6:13 ` [PATCH 22/24] ASoC: codecs: cs47l92: " phucduc.bui
2026-06-26 12:04   ` Charles Keepax
2026-06-26  6:13 ` [PATCH 23/24] ASoC: codecs: cs48l32: " phucduc.bui
2026-06-26 12:15   ` Charles Keepax
2026-06-26  6:13 ` [PATCH 24/24] ASoC: codecs: cs2072x: " 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=20260626061329.23264-4-phucduc.bui@gmail.com \
    --to=phucduc.bui@gmail.com \
    --cc=asahi@lists.linux.dev \
    --cc=bleung@chromium.org \
    --cc=broonie@kernel.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=cychiang@chromium.org \
    --cc=david.rhodes@cirrus.com \
    --cc=groeck@chromium.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=perex@perex.cz \
    --cc=povik+lin@cutebit.org \
    --cc=rf@opensource.cirrus.com \
    --cc=tiwai@suse.com \
    --cc=tzungbi@kernel.org \
    /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.