From: phucduc.bui@gmail.com
To: peter.ujfalusi@gmail.com, broonie@kernel.org
Cc: lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com,
jarkko.nikula@bitmer.com, linux-sound@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org,
bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH 2/7] ASoC: ti: omap-dmic: Use guard() for mutex locks
Date: Fri, 8 May 2026 17:38:32 +0700 [thread overview]
Message-ID: <20260508103837.138142-3-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260508103837.138142-1-phucduc.bui@gmail.com>
From: bui duc phuc <phucduc.bui@gmail.com>
Replace open-coded mutex_lock()/mutex_unlock() pairs with guard(mutex)()
and scoped_guard() helpers.
This also simplifies the control flow by removing temporary return
variables and unnecessary goto-based cleanup paths.
No functional change intended.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/ti/omap-dmic.c | 44 ++++++++++++++++------------------------
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/sound/soc/ti/omap-dmic.c b/sound/soc/ti/omap-dmic.c
index fb92bb88eb5c..dc92fdb89a0f 100644
--- a/sound/soc/ti/omap-dmic.c
+++ b/sound/soc/ti/omap-dmic.c
@@ -91,18 +91,14 @@ static int omap_dmic_dai_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct omap_dmic *dmic = snd_soc_dai_get_drvdata(dai);
- int ret = 0;
-
- mutex_lock(&dmic->mutex);
- if (!snd_soc_dai_active(dai))
- dmic->active = 1;
- else
- ret = -EBUSY;
+ guard(mutex)(&dmic->mutex);
- mutex_unlock(&dmic->mutex);
+ if (snd_soc_dai_active(dai))
+ return -EBUSY;
- return ret;
+ dmic->active = 1;
+ return 0;
}
static void omap_dmic_dai_shutdown(struct snd_pcm_substream *substream,
@@ -110,14 +106,12 @@ static void omap_dmic_dai_shutdown(struct snd_pcm_substream *substream,
{
struct omap_dmic *dmic = snd_soc_dai_get_drvdata(dai);
- mutex_lock(&dmic->mutex);
+ guard(mutex)(&dmic->mutex);
cpu_latency_qos_remove_request(&dmic->pm_qos_req);
if (!snd_soc_dai_active(dai))
dmic->active = 0;
-
- mutex_unlock(&dmic->mutex);
}
static int omap_dmic_select_divider(struct omap_dmic *dmic, int sample_rate)
@@ -334,26 +328,24 @@ static int omap_dmic_select_fclk(struct omap_dmic *dmic, int clk_id,
return -ENODEV;
}
- mutex_lock(&dmic->mutex);
- if (dmic->active) {
- /* disable clock while reparenting */
- pm_runtime_put_sync(dmic->dev);
- ret = clk_set_parent(mux, parent_clk);
- pm_runtime_get_sync(dmic->dev);
- } else {
- ret = clk_set_parent(mux, parent_clk);
+ scoped_guard(mutex, &dmic->mutex) {
+ if (dmic->active) {
+ /* disable clock while reparenting */
+ pm_runtime_put_sync(dmic->dev);
+ ret = clk_set_parent(mux, parent_clk);
+ pm_runtime_get_sync(dmic->dev);
+ } else {
+ ret = clk_set_parent(mux, parent_clk);
+ }
}
- mutex_unlock(&dmic->mutex);
if (ret < 0) {
dev_err(dmic->dev, "re-parent failed\n");
- goto err_busy;
+ } else {
+ dmic->sysclk = clk_id;
+ dmic->fclk_freq = freq;
}
- dmic->sysclk = clk_id;
- dmic->fclk_freq = freq;
-
-err_busy:
clk_put(mux);
clk_put(parent_clk);
--
2.43.0
next prev parent reply other threads:[~2026-05-08 10:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 10:38 [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers phucduc.bui
2026-05-08 10:38 ` [PATCH 1/7] ASoC: ti: j721e-evm: Use guard() for mutex locks phucduc.bui
2026-05-08 10:38 ` phucduc.bui [this message]
2026-05-08 10:38 ` [PATCH 3/7] ASoC: ti: omap-hdmi: " phucduc.bui
2026-05-08 10:38 ` [PATCH 4/7] ASoC: ti: omap-mcpdm: " phucduc.bui
2026-05-08 10:38 ` [PATCH 5/7] ASoC: ti: ams-delta: Use guard() for spin locks phucduc.bui
2026-05-08 10:38 ` [PATCH 6/7] ASoC: ti: omap-mcbsp-st: " phucduc.bui
2026-05-09 12:26 ` Jarkko Nikula
2026-05-08 10:38 ` [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling phucduc.bui
2026-05-10 1:35 ` Mark Brown
2026-05-11 4:44 ` Bui Duc Phuc
2026-05-09 12:28 ` [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers Jarkko Nikula
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=20260508103837.138142-3-phucduc.bui@gmail.com \
--to=phucduc.bui@gmail.com \
--cc=broonie@kernel.org \
--cc=jarkko.nikula@bitmer.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=peter.ujfalusi@gmail.com \
--cc=tiwai@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox