From: phucduc.bui@gmail.com
To: Mark Brown <broonie@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Cheng-Yi Chiang <cychiang@chromium.org>,
Tzung-Bi Shih <tzungbi@kernel.org>,
Guenter Roeck <groeck@chromium.org>,
Benson Leung <bleung@chromium.org>,
David Rhodes <david.rhodes@cirrus.com>,
Richard Fitzgerald <rf@opensource.cirrus.com>,
povik+lin@cutebit.org,
Charles Keepax <ckeepax@opensource.cirrus.com>,
Support Opensource <support.opensource@diasemi.com>,
Nick Li <nick.li@foursemi.com>,
Herve Codina <herve.codina@bootlin.com>,
Srinivas Kandagatla <srini@kernel.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Shenghao Ding <shenghao-ding@ti.com>, Kevin Lu <kevin-lu@ti.com>,
Baojun Xu <baojun.xu@ti.com>, Sen Wang <sen@ti.com>,
Oder Chiou <oder_chiou@realtek.com>,
Lars-Peter Clausen <lars@metafoo.de>,
nuno.sa@analog.com,
Steven Eckhoff <steven.eckhoff.opensource@gmail.com>,
patches@opensource.cirrus.com, chrome-platform@lists.linux.dev,
asahi@lists.linux.dev, linux-arm-msm@vger.kernel.org,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH 03/78] ASoC: codecs: arizona-jack: Use guard() for mutex locks
Date: Wed, 17 Jun 2026 17:31:20 +0700 [thread overview]
Message-ID: <20260617103235.449609-4-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260617103235.449609-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/arizona-jack.c | 194 +++++++++++++++-----------------
1 file changed, 92 insertions(+), 102 deletions(-)
diff --git a/sound/soc/codecs/arizona-jack.c b/sound/soc/codecs/arizona-jack.c
index a9063bac2752..fc09b31943a6 100644
--- a/sound/soc/codecs/arizona-jack.c
+++ b/sound/soc/codecs/arizona-jack.c
@@ -528,12 +528,11 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
int ret, reading, state, report;
bool mic = false;
- mutex_lock(&info->lock);
+ guard(mutex)(&info->lock);
/* If we got a spurious IRQ for some reason then ignore it */
if (!info->hpdet_active) {
dev_warn(arizona->dev, "Spurious HPDET IRQ\n");
- mutex_unlock(&info->lock);
return IRQ_NONE;
}
@@ -546,7 +545,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
ret = arizona_hpdet_read(info);
if (ret == -EAGAIN)
- goto out;
+ return IRQ_HANDLED;
else if (ret < 0)
goto done;
reading = ret;
@@ -559,7 +558,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
ret = arizona_hpdet_do_id(info, &reading, &mic);
if (ret == -EAGAIN)
- goto out;
+ return IRQ_HANDLED;
else if (ret < 0)
goto done;
@@ -596,9 +595,6 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
if (state)
info->hpdet_done = true;
-out:
- mutex_unlock(&info->lock);
-
return IRQ_HANDLED;
}
@@ -707,15 +703,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 +915,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 +929,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 +940,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 +961,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)
@@ -1013,6 +1004,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
struct arizona *arizona = info->arizona;
unsigned int val, present, mask;
bool cancelled_hp, cancelled_mic;
+ irqreturn_t ret_irq = IRQ_HANDLED;
int ret, i;
cancelled_hp = cancel_delayed_work_sync(&info->hpdet_work);
@@ -1020,110 +1012,108 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
pm_runtime_get_sync(arizona->dev);
- mutex_lock(&info->lock);
-
- if (info->micd_clamp) {
- mask = ARIZONA_MICD_CLAMP_STS;
- present = 0;
- } else {
- mask = ARIZONA_JD1_STS;
- if (arizona->pdata.jd_invert)
+ scoped_guard(mutex, &info->lock) {
+ if (info->micd_clamp) {
+ mask = ARIZONA_MICD_CLAMP_STS;
present = 0;
- else
- present = ARIZONA_JD1_STS;
- }
+ } else {
+ mask = ARIZONA_JD1_STS;
+ if (arizona->pdata.jd_invert)
+ present = 0;
+ else
+ present = ARIZONA_JD1_STS;
+ }
- 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;
- }
+ 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);
+ ret_irq = IRQ_NONE;
+ break;
+ }
- val &= mask;
- if (val == info->last_jackdet) {
- dev_dbg(arizona->dev, "Suppressing duplicate JACKDET\n");
- if (cancelled_hp)
- queue_delayed_work(system_power_efficient_wq,
- &info->hpdet_work,
- msecs_to_jiffies(HPDET_DEBOUNCE));
+ val &= mask;
+ if (val == info->last_jackdet) {
+ dev_dbg(arizona->dev, "Suppressing duplicate JACKDET\n");
+ if (cancelled_hp)
+ queue_delayed_work(system_power_efficient_wq,
+ &info->hpdet_work,
+ msecs_to_jiffies(HPDET_DEBOUNCE));
- if (cancelled_mic) {
- int micd_timeout = arizona->pdata.micd_timeout;
+ if (cancelled_mic) {
+ int micd_timeout = arizona->pdata.micd_timeout;
- queue_delayed_work(system_power_efficient_wq,
- &info->micd_timeout_work,
- msecs_to_jiffies(micd_timeout));
+ queue_delayed_work(system_power_efficient_wq,
+ &info->micd_timeout_work,
+ msecs_to_jiffies(micd_timeout));
+ }
+
+ goto out;
}
+ info->last_jackdet = val;
- goto out;
- }
- info->last_jackdet = val;
+ if (info->last_jackdet == present) {
+ dev_dbg(arizona->dev, "Detected jack\n");
+ snd_soc_jack_report(info->jack, SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
- if (info->last_jackdet == present) {
- dev_dbg(arizona->dev, "Detected jack\n");
- snd_soc_jack_report(info->jack, SND_JACK_MECHANICAL, SND_JACK_MECHANICAL);
+ info->detecting = true;
+ info->mic = false;
+ info->jack_flips = 0;
- info->detecting = true;
- info->mic = false;
- info->jack_flips = 0;
+ if (!arizona->pdata.hpdet_acc_id) {
+ arizona_start_mic(info);
+ } else {
+ queue_delayed_work(system_power_efficient_wq,
+ &info->hpdet_work,
+ msecs_to_jiffies(HPDET_DEBOUNCE));
+ }
- if (!arizona->pdata.hpdet_acc_id) {
- arizona_start_mic(info);
+ if (info->micd_clamp || !arizona->pdata.jd_invert)
+ regmap_update_bits(arizona->regmap,
+ ARIZONA_JACK_DETECT_DEBOUNCE,
+ ARIZONA_MICD_CLAMP_DB |
+ ARIZONA_JD1_DB, 0);
} else {
- queue_delayed_work(system_power_efficient_wq,
- &info->hpdet_work,
- msecs_to_jiffies(HPDET_DEBOUNCE));
- }
+ dev_dbg(arizona->dev, "Detected jack removal\n");
- if (info->micd_clamp || !arizona->pdata.jd_invert)
- regmap_update_bits(arizona->regmap,
- ARIZONA_JACK_DETECT_DEBOUNCE,
- ARIZONA_MICD_CLAMP_DB |
- ARIZONA_JD1_DB, 0);
- } else {
- dev_dbg(arizona->dev, "Detected jack removal\n");
+ arizona_stop_mic(info);
- arizona_stop_mic(info);
+ info->num_hpdet_res = 0;
+ for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++)
+ info->hpdet_res[i] = 0;
+ info->mic = false;
+ info->hpdet_done = false;
+ info->hpdet_retried = false;
- info->num_hpdet_res = 0;
- for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++)
- info->hpdet_res[i] = 0;
- info->mic = false;
- info->hpdet_done = false;
- info->hpdet_retried = false;
-
- snd_soc_jack_report(info->jack, 0, ARIZONA_JACK_MASK | info->micd_button_mask);
+ snd_soc_jack_report(info->jack, 0,
+ ARIZONA_JACK_MASK | info->micd_button_mask);
- /*
- * If the jack was removed during a headphone detection we
- * need to wait for the headphone detection to finish, as
- * it can not be aborted. We don't want to be able to start
- * a new headphone detection from a fresh insert until this
- * one is finished.
- */
- arizona_hpdet_wait(info);
+ /*
+ * If the jack was removed during a headphone detection we
+ * need to wait for the headphone detection to finish, as
+ * it can not be aborted. We don't want to be able to start
+ * a new headphone detection from a fresh insert until this
+ * one is finished.
+ */
+ arizona_hpdet_wait(info);
- regmap_update_bits(arizona->regmap,
- ARIZONA_JACK_DETECT_DEBOUNCE,
- ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB,
- ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB);
- }
+ regmap_update_bits(arizona->regmap,
+ ARIZONA_JACK_DETECT_DEBOUNCE,
+ ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB,
+ 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 |
- ARIZONA_MICD_CLAMP_RISE_TRIG_STS |
- ARIZONA_JD1_FALL_TRIG_STS |
- ARIZONA_JD1_RISE_TRIG_STS);
-
- mutex_unlock(&info->lock);
+ /* 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);
+ }
pm_runtime_put_autosuspend(arizona->dev);
- return IRQ_HANDLED;
+ return ret_irq;
}
/* Map a level onto a slot in the register bank */
--
2.43.0
next prev parent reply other threads:[~2026-06-17 10:33 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 10:31 [PATCH 00/78] ASoC: codecs: Use guard() for mutex & spin locks phucduc.bui
2026-06-17 10:31 ` [PATCH 01/78] ASoC: codecs: ab8500: Use guard() for mutex locks phucduc.bui
2026-06-17 10:31 ` [PATCH 02/78] ASoC: codecs: ak4613: " phucduc.bui
2026-06-17 10:31 ` phucduc.bui [this message]
2026-06-17 10:31 ` [PATCH 04/78] ASoC: codecs: arizona: " phucduc.bui
2026-06-17 10:31 ` [PATCH 05/78] ASoC: codecs: aw87390: " phucduc.bui
2026-06-17 10:31 ` [PATCH 06/78] ASoC: codecs: aw88081: " phucduc.bui
2026-06-17 10:31 ` [PATCH 07/78] ASoC: codecs: aw88166: " phucduc.bui
2026-06-17 10:31 ` [PATCH 08/78] ASoC: codecs: aw88261: " phucduc.bui
2026-06-17 10:31 ` [PATCH 09/78] ASoC: codecs: aw88395: " phucduc.bui
2026-06-17 10:31 ` [PATCH 10/78] ASoC: codecs: aw88399: " phucduc.bui
2026-06-17 10:31 ` [PATCH 11/78] ASoC: codecs: cros_ec_codec: " phucduc.bui
2026-06-17 10:31 ` [PATCH 12/78] ASoC: codecs: cs-amp-lib: " phucduc.bui
2026-06-17 10:31 ` [PATCH 13/78] ASoC: codecs: cs35l56: " phucduc.bui
2026-06-17 10:31 ` [PATCH 14/78] ASoC: codecs: cs42l42: " phucduc.bui
2026-06-17 10:31 ` [PATCH 15/78] ASoC: codecs: cs42l43: " phucduc.bui
2026-06-17 10:57 ` Charles Keepax
2026-06-17 13:02 ` David Laight
2026-06-17 10:31 ` [PATCH 16/78] ASoC: codecs: cs42l84: " phucduc.bui
2026-06-17 10:31 ` [PATCH 17/78] ASoC: codecs: cs43130: " phucduc.bui
2026-06-17 10:31 ` [PATCH 18/78] ASoC: codecs: cs47l15: " phucduc.bui
2026-06-17 10:31 ` [PATCH 19/78] ASoC: codecs: cs47l35: " phucduc.bui
2026-06-17 10:31 ` [PATCH 20/78] ASoC: codecs: cs47l85: " phucduc.bui
2026-06-17 10:31 ` [PATCH 21/78] ASoC: codecs: cs47l90: " phucduc.bui
2026-06-17 10:31 ` [PATCH 22/78] ASoC: codecs: cs47l92: " phucduc.bui
2026-06-17 10:31 ` [PATCH 23/78] ASoC: codecs: cs48l32: " phucduc.bui
2026-06-17 10:31 ` [PATCH 24/78] ASoC: codecs: cs2072x: " phucduc.bui
2026-06-17 10:31 ` [PATCH 25/78] ASoC: codecs: da7213: " phucduc.bui
2026-06-17 10:31 ` [PATCH 26/78] ASoC: codecs: da7219: " phucduc.bui
2026-06-17 10:31 ` [PATCH 27/78] ASoC: codecs: es8316: " phucduc.bui
2026-06-17 10:31 ` [PATCH 28/78] ASoC: codecs: es8326: " phucduc.bui
2026-06-17 10:31 ` [PATCH 29/78] ASoC: codecs: es9356: " phucduc.bui
2026-06-17 10:31 ` [PATCH 30/78] ASoC: codecs: fs210x: " phucduc.bui
2026-06-17 10:31 ` [PATCH 31/78] ASoC: codecs: hdac_hdmi: " phucduc.bui
2026-06-17 10:31 ` [PATCH 32/78] ASoC: codecs: hdmi-codec: " phucduc.bui
2026-06-17 10:31 ` [PATCH 33/78] ASoC: codecs: idt821034: " phucduc.bui
2026-06-17 10:31 ` [PATCH 34/78] ASoC: codecs: lpass-macro: " phucduc.bui
2026-06-17 10:31 ` [PATCH 35/78] ASoC: codecs: madera: " phucduc.bui
2026-06-17 10:31 ` [PATCH 36/78] ASoC: codecs: max98095: " phucduc.bui
2026-06-17 10:31 ` [PATCH 37/78] ASoC: codecs: mt6359-accdet: " phucduc.bui
2026-06-17 10:31 ` [PATCH 38/78] ASoC: codecs: pcm512x: " phucduc.bui
2026-06-17 10:31 ` [PATCH 39/78] ASoC: codecs: pcm6240: " phucduc.bui
2026-06-17 10:31 ` [PATCH 40/78] ASoC: codecs: peb2466: " phucduc.bui
2026-06-17 10:31 ` [PATCH 41/78] ASoC: codecs: rt5514-spi: " phucduc.bui
2026-06-17 10:31 ` [PATCH 42/78] ASoC: codecs: rt5645: " phucduc.bui
2026-06-17 10:32 ` [PATCH 43/78] ASoC: codecs: rt5665: " phucduc.bui
2026-06-17 10:32 ` [PATCH 44/78] ASoC: codecs: rt5668: " phucduc.bui
2026-06-17 10:32 ` [PATCH 45/78] ASoC: codecs: rt5677: " phucduc.bui
2026-06-17 10:32 ` [PATCH 46/78] ASoC: codecs: rt5682: " phucduc.bui
2026-06-17 10:32 ` [PATCH 47/78] ASoC: codecs: rt700: " phucduc.bui
2026-06-17 10:32 ` [PATCH 48/78] ASoC: codecs: rt711: " phucduc.bui
2026-06-17 10:32 ` [PATCH 49/78] ASoC: codecs: rt712: " phucduc.bui
2026-06-17 10:32 ` [PATCH 50/78] ASoC: codecs: rt721: " phucduc.bui
2026-06-17 10:32 ` [PATCH 51/78] ASoC: codecs: rt722: " phucduc.bui
2026-06-17 10:32 ` [PATCH 52/78] ASoC: codecs: sigmadsp: " phucduc.bui
2026-06-17 10:32 ` [PATCH 53/78] ASoC: codecs: sta350: " phucduc.bui
2026-06-17 10:32 ` [PATCH 54/78] ASoC: codecs: sta32x: " phucduc.bui
2026-06-17 10:32 ` [PATCH 55/78] ASoC: codecs: tas2781: " 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=20260617103235.449609-4-phucduc.bui@gmail.com \
--to=phucduc.bui@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=asahi@lists.linux.dev \
--cc=baojun.xu@ti.com \
--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=herve.codina@bootlin.com \
--cc=kevin-lu@ti.com \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-sound@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=nick.li@foursemi.com \
--cc=nuno.sa@analog.com \
--cc=oder_chiou@realtek.com \
--cc=patches@opensource.cirrus.com \
--cc=perex@perex.cz \
--cc=povik+lin@cutebit.org \
--cc=rf@opensource.cirrus.com \
--cc=sen@ti.com \
--cc=shenghao-ding@ti.com \
--cc=srini@kernel.org \
--cc=steven.eckhoff.opensource@gmail.com \
--cc=support.opensource@diasemi.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.