* [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers
@ 2026-05-08 10:38 phucduc.bui
2026-05-08 10:38 ` [PATCH 1/7] ASoC: ti: j721e-evm: Use guard() for mutex locks phucduc.bui
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: phucduc.bui @ 2026-05-08 10:38 UTC (permalink / raw)
To: peter.ujfalusi, broonie
Cc: lgirdwood, perex, tiwai, jarkko.nikula, linux-sound, linux-kernel,
linux-omap, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Hi all,
This series converts mutex and spinlock handling in TI ASoC drivers
to use guard() helpers.
Most patches are straightforward conversions to guard() helpers.
Two patches include minor cleanup changes in the process:
omap-dmic: Simplified omap_dmic_dai_startup() by removing the
temporary return variable and using a direct return path on error.
omap-mcbsp: Modernized omap_mcbsp_request() by using __free(kfree)
for memory management. This ensures that memory is always freed on
error paths after the spinlock is released, without needing manual
goto labels.
No behavior change intended.
Best regards,
Phuc
bui duc phuc (7):
ASoC: ti: j721e-evm: Use guard() for mutex locks
ASoC: ti: omap-dmic: Use guard() for mutex locks
ASoC: ti: omap-hdmi: Use guard() for mutex locks
ASoC: ti: omap-mcpdm: Use guard() for mutex locks
ASoC: ti: ams-delta: Use guard() for spin locks
ASoC: ti: omap-mcbsp-st: Use guard() for spin locks
ASoC: ti: omap-mcbsp: Simplify lock and resource handling
sound/soc/ti/ams-delta.c | 26 ++++++++---------
sound/soc/ti/j721e-evm.c | 25 ++++++-----------
sound/soc/ti/omap-dmic.c | 44 ++++++++++++-----------------
sound/soc/ti/omap-hdmi.c | 18 +++++-------
sound/soc/ti/omap-mcbsp-st.c | 26 ++++++-----------
sound/soc/ti/omap-mcbsp.c | 54 ++++++++++++++++--------------------
sound/soc/ti/omap-mcpdm.c | 8 ++----
7 files changed, 81 insertions(+), 120 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/7] ASoC: ti: j721e-evm: Use guard() for mutex locks
2026-05-08 10:38 [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers phucduc.bui
@ 2026-05-08 10:38 ` phucduc.bui
2026-05-08 10:38 ` [PATCH 2/7] ASoC: ti: omap-dmic: " phucduc.bui
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: phucduc.bui @ 2026-05-08 10:38 UTC (permalink / raw)
To: peter.ujfalusi, broonie
Cc: lgirdwood, perex, tiwai, jarkko.nikula, linux-sound, linux-kernel,
linux-omap, bui duc phuc
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/ti/j721e-evm.c | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/sound/soc/ti/j721e-evm.c b/sound/soc/ti/j721e-evm.c
index faa62c1a9b8e..8a3333aa32ee 100644
--- a/sound/soc/ti/j721e-evm.c
+++ b/sound/soc/ti/j721e-evm.c
@@ -263,7 +263,7 @@ static int j721e_audio_startup(struct snd_pcm_substream *substream)
int ret = 0;
int i;
- mutex_lock(&priv->mutex);
+ guard(mutex)(&priv->mutex);
domain->active++;
@@ -303,7 +303,6 @@ static int j721e_audio_startup(struct snd_pcm_substream *substream)
out:
if (ret)
domain->active--;
- mutex_unlock(&priv->mutex);
return ret;
}
@@ -323,30 +322,28 @@ static int j721e_audio_hw_params(struct snd_pcm_substream *substream,
int ret;
int i;
- mutex_lock(&priv->mutex);
+ guard(mutex)(&priv->mutex);
- if (domain->rate && domain->rate != params_rate(params)) {
- ret = -EINVAL;
- goto out;
- }
+ if (domain->rate && domain->rate != params_rate(params))
+ return -EINVAL;
if (params_width(params) == 16)
slot_width = 16;
ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, slot_width);
if (ret && ret != -ENOTSUPP)
- goto out;
+ return ret;
for_each_rtd_codec_dais(rtd, i, codec_dai) {
ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 0x3, 2,
slot_width);
if (ret && ret != -ENOTSUPP)
- goto out;
+ return ret;
}
ret = j721e_configure_refclk(priv, domain_id, params_rate(params));
if (ret)
- goto out;
+ return ret;
sysclk_rate = priv->hsdiv_rates[domain->parent_clk_id];
for_each_rtd_codec_dais(rtd, i, codec_dai) {
@@ -356,7 +353,7 @@ static int j721e_audio_hw_params(struct snd_pcm_substream *substream,
dev_err(priv->dev,
"codec set_sysclk failed for %u Hz\n",
sysclk_rate);
- goto out;
+ return ret;
}
}
@@ -371,8 +368,6 @@ static int j721e_audio_hw_params(struct snd_pcm_substream *substream,
ret = 0;
}
-out:
- mutex_unlock(&priv->mutex);
return ret;
}
@@ -383,15 +378,13 @@ static void j721e_audio_shutdown(struct snd_pcm_substream *substream)
unsigned int domain_id = rtd->dai_link->id;
struct j721e_audio_domain *domain = &priv->audio_domains[domain_id];
- mutex_lock(&priv->mutex);
+ guard(mutex)(&priv->mutex);
domain->active--;
if (!domain->active) {
domain->rate = 0;
domain->active_link = 0;
}
-
- mutex_unlock(&priv->mutex);
}
static const struct snd_soc_ops j721e_audio_ops = {
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/7] ASoC: ti: omap-dmic: Use guard() for mutex locks
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
2026-05-08 10:38 ` [PATCH 3/7] ASoC: ti: omap-hdmi: " phucduc.bui
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: phucduc.bui @ 2026-05-08 10:38 UTC (permalink / raw)
To: peter.ujfalusi, broonie
Cc: lgirdwood, perex, tiwai, jarkko.nikula, linux-sound, linux-kernel,
linux-omap, bui duc phuc
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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/7] ASoC: ti: omap-hdmi: Use guard() for mutex locks
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 ` [PATCH 2/7] ASoC: ti: omap-dmic: " phucduc.bui
@ 2026-05-08 10:38 ` phucduc.bui
2026-05-08 10:38 ` [PATCH 4/7] ASoC: ti: omap-mcpdm: " phucduc.bui
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: phucduc.bui @ 2026-05-08 10:38 UTC (permalink / raw)
To: peter.ujfalusi, broonie
Cc: lgirdwood, perex, tiwai, jarkko.nikula, linux-sound, linux-kernel,
linux-omap, bui duc phuc
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/ti/omap-hdmi.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/sound/soc/ti/omap-hdmi.c b/sound/soc/ti/omap-hdmi.c
index 55e7cb96858f..e60f5b483fc5 100644
--- a/sound/soc/ti/omap-hdmi.c
+++ b/sound/soc/ti/omap-hdmi.c
@@ -49,7 +49,7 @@ static void hdmi_dai_abort(struct device *dev)
{
struct hdmi_audio_data *ad = dev_get_drvdata(dev);
- mutex_lock(&ad->current_stream_lock);
+ guard(mutex)(&ad->current_stream_lock);
if (ad->current_stream && ad->current_stream->runtime &&
snd_pcm_running(ad->current_stream)) {
dev_err(dev, "HDMI display disabled, aborting playback\n");
@@ -57,7 +57,6 @@ static void hdmi_dai_abort(struct device *dev)
snd_pcm_stop(ad->current_stream, SNDRV_PCM_STATE_DISCONNECTED);
snd_pcm_stream_unlock_irq(ad->current_stream);
}
- mutex_unlock(&ad->current_stream_lock);
}
static int hdmi_dai_startup(struct snd_pcm_substream *substream,
@@ -86,16 +85,14 @@ static int hdmi_dai_startup(struct snd_pcm_substream *substream,
snd_soc_dai_set_dma_data(dai, substream, &ad->dma_data);
- mutex_lock(&ad->current_stream_lock);
- ad->current_stream = substream;
- mutex_unlock(&ad->current_stream_lock);
+ scoped_guard(mutex, &ad->current_stream_lock)
+ ad->current_stream = substream;
ret = ad->ops->audio_startup(ad->dssdev, hdmi_dai_abort);
if (ret) {
- mutex_lock(&ad->current_stream_lock);
- ad->current_stream = NULL;
- mutex_unlock(&ad->current_stream_lock);
+ scoped_guard(mutex, &ad->current_stream_lock)
+ ad->current_stream = NULL;
}
return ret;
@@ -261,9 +258,8 @@ static void hdmi_dai_shutdown(struct snd_pcm_substream *substream,
ad->ops->audio_shutdown(ad->dssdev);
- mutex_lock(&ad->current_stream_lock);
- ad->current_stream = NULL;
- mutex_unlock(&ad->current_stream_lock);
+ scoped_guard(mutex, &ad->current_stream_lock)
+ ad->current_stream = NULL;
}
static const struct snd_soc_dai_ops hdmi_dai_ops = {
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/7] ASoC: ti: omap-mcpdm: Use guard() for mutex locks
2026-05-08 10:38 [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers phucduc.bui
` (2 preceding siblings ...)
2026-05-08 10:38 ` [PATCH 3/7] ASoC: ti: omap-hdmi: " phucduc.bui
@ 2026-05-08 10:38 ` phucduc.bui
2026-05-08 10:38 ` [PATCH 5/7] ASoC: ti: ams-delta: Use guard() for spin locks phucduc.bui
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: phucduc.bui @ 2026-05-08 10:38 UTC (permalink / raw)
To: peter.ujfalusi, broonie
Cc: lgirdwood, perex, tiwai, jarkko.nikula, linux-sound, linux-kernel,
linux-omap, bui duc phuc
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/ti/omap-mcpdm.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/sound/soc/ti/omap-mcpdm.c b/sound/soc/ti/omap-mcpdm.c
index 1a5d19937c64..c7d7b502f120 100644
--- a/sound/soc/ti/omap-mcpdm.c
+++ b/sound/soc/ti/omap-mcpdm.c
@@ -251,13 +251,11 @@ static int omap_mcpdm_dai_startup(struct snd_pcm_substream *substream,
{
struct omap_mcpdm *mcpdm = snd_soc_dai_get_drvdata(dai);
- mutex_lock(&mcpdm->mutex);
+ guard(mutex)(&mcpdm->mutex);
if (!snd_soc_dai_active(dai))
omap_mcpdm_open_streams(mcpdm);
- mutex_unlock(&mcpdm->mutex);
-
return 0;
}
@@ -269,7 +267,7 @@ static void omap_mcpdm_dai_shutdown(struct snd_pcm_substream *substream,
int stream1 = tx ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE;
int stream2 = tx ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
- mutex_lock(&mcpdm->mutex);
+ guard(mutex)(&mcpdm->mutex);
if (!snd_soc_dai_active(dai)) {
if (omap_mcpdm_active(mcpdm)) {
@@ -287,8 +285,6 @@ static void omap_mcpdm_dai_shutdown(struct snd_pcm_substream *substream,
cpu_latency_qos_remove_request(&mcpdm->pm_qos_req);
mcpdm->latency[stream1] = 0;
-
- mutex_unlock(&mcpdm->mutex);
}
static int omap_mcpdm_dai_hw_params(struct snd_pcm_substream *substream,
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 5/7] ASoC: ti: ams-delta: Use guard() for spin locks
2026-05-08 10:38 [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers phucduc.bui
` (3 preceding siblings ...)
2026-05-08 10:38 ` [PATCH 4/7] ASoC: ti: omap-mcpdm: " phucduc.bui
@ 2026-05-08 10:38 ` phucduc.bui
2026-05-08 10:38 ` [PATCH 6/7] ASoC: ti: omap-mcbsp-st: " phucduc.bui
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: phucduc.bui @ 2026-05-08 10:38 UTC (permalink / raw)
To: peter.ujfalusi, broonie
Cc: lgirdwood, perex, tiwai, jarkko.nikula, linux-sound, linux-kernel,
linux-omap, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/ti/ams-delta.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/sound/soc/ti/ams-delta.c b/sound/soc/ti/ams-delta.c
index ba173d9fcba9..6dd0d051a757 100644
--- a/sound/soc/ti/ams-delta.c
+++ b/sound/soc/ti/ams-delta.c
@@ -264,10 +264,10 @@ static void cx81801_timeout(struct timer_list *unused)
{
int muted;
- spin_lock(&ams_delta_lock);
- cx81801_cmd_pending = 0;
- muted = ams_delta_muted;
- spin_unlock(&ams_delta_lock);
+ scoped_guard(spinlock, &ams_delta_lock) {
+ cx81801_cmd_pending = 0;
+ muted = ams_delta_muted;
+ }
/* Reconnect the codec DAI back from the modem to the CPU DAI
* only if digital mute still off */
@@ -373,11 +373,11 @@ static void cx81801_receive(struct tty_struct *tty, const u8 *cp, const u8 *fp,
continue;
/* Complete modem response received, apply config to codec */
- spin_lock_bh(&ams_delta_lock);
- mod_timer(&cx81801_timer, jiffies + msecs_to_jiffies(150));
- apply = !ams_delta_muted && !cx81801_cmd_pending;
- cx81801_cmd_pending = 1;
- spin_unlock_bh(&ams_delta_lock);
+ scoped_guard(spinlock_bh, &ams_delta_lock) {
+ mod_timer(&cx81801_timer, jiffies + msecs_to_jiffies(150));
+ apply = !ams_delta_muted && !cx81801_cmd_pending;
+ cx81801_cmd_pending = 1;
+ }
/* Apply config pulse by connecting the codec to the modem
* if not already done */
@@ -426,10 +426,10 @@ static int ams_delta_mute(struct snd_soc_dai *dai, int mute, int direction)
if (ams_delta_muted == mute)
return 0;
- spin_lock_bh(&ams_delta_lock);
- ams_delta_muted = mute;
- apply = !cx81801_cmd_pending;
- spin_unlock_bh(&ams_delta_lock);
+ scoped_guard(spinlock_bh, &ams_delta_lock) {
+ ams_delta_muted = mute;
+ apply = !cx81801_cmd_pending;
+ }
if (apply)
gpiod_set_value(gpiod_modem_codec, !!mute);
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 6/7] ASoC: ti: omap-mcbsp-st: Use guard() for spin locks
2026-05-08 10:38 [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers phucduc.bui
` (4 preceding siblings ...)
2026-05-08 10:38 ` [PATCH 5/7] ASoC: ti: ams-delta: Use guard() for spin locks phucduc.bui
@ 2026-05-08 10:38 ` 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-09 12:28 ` [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers Jarkko Nikula
7 siblings, 1 reply; 12+ messages in thread
From: phucduc.bui @ 2026-05-08 10:38 UTC (permalink / raw)
To: peter.ujfalusi, broonie
Cc: lgirdwood, perex, tiwai, jarkko.nikula, linux-sound, linux-kernel,
linux-omap, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/ti/omap-mcbsp-st.c | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
diff --git a/sound/soc/ti/omap-mcbsp-st.c b/sound/soc/ti/omap-mcbsp-st.c
index 901578896ef3..b762d5d3e33b 100644
--- a/sound/soc/ti/omap-mcbsp-st.c
+++ b/sound/soc/ti/omap-mcbsp-st.c
@@ -156,7 +156,7 @@ static int omap_mcbsp_st_set_chgain(struct omap_mcbsp *mcbsp, int channel,
if (!st_data)
return -ENOENT;
- spin_lock_irq(&mcbsp->lock);
+ guard(spinlock_irq)(&mcbsp->lock);
if (channel == 0)
st_data->ch0gain = chgain;
else if (channel == 1)
@@ -166,7 +166,6 @@ static int omap_mcbsp_st_set_chgain(struct omap_mcbsp *mcbsp, int channel,
if (st_data->enabled)
omap_mcbsp_st_chgain(mcbsp);
- spin_unlock_irq(&mcbsp->lock);
return ret;
}
@@ -180,14 +179,13 @@ static int omap_mcbsp_st_get_chgain(struct omap_mcbsp *mcbsp, int channel,
if (!st_data)
return -ENOENT;
- spin_lock_irq(&mcbsp->lock);
+ guard(spinlock_irq)(&mcbsp->lock);
if (channel == 0)
*chgain = st_data->ch0gain;
else if (channel == 1)
*chgain = st_data->ch1gain;
else
ret = -EINVAL;
- spin_unlock_irq(&mcbsp->lock);
return ret;
}
@@ -199,10 +197,9 @@ static int omap_mcbsp_st_enable(struct omap_mcbsp *mcbsp)
if (!st_data)
return -ENODEV;
- spin_lock_irq(&mcbsp->lock);
+ guard(spinlock_irq)(&mcbsp->lock);
st_data->enabled = 1;
omap_mcbsp_st_start(mcbsp);
- spin_unlock_irq(&mcbsp->lock);
return 0;
}
@@ -215,10 +212,9 @@ static int omap_mcbsp_st_disable(struct omap_mcbsp *mcbsp)
if (!st_data)
return -ENODEV;
- spin_lock_irq(&mcbsp->lock);
+ guard(spinlock_irq)(&mcbsp->lock);
omap_mcbsp_st_stop(mcbsp);
st_data->enabled = 0;
- spin_unlock_irq(&mcbsp->lock);
return ret;
}
@@ -241,13 +237,12 @@ static ssize_t st_taps_show(struct device *dev,
ssize_t status = 0;
int i;
- spin_lock_irq(&mcbsp->lock);
+ guard(spinlock_irq)(&mcbsp->lock);
for (i = 0; i < st_data->nr_taps; i++)
status += sysfs_emit_at(buf, status, (i ? ", %d" : "%d"),
st_data->taps[i]);
if (i)
status += sysfs_emit_at(buf, status, "\n");
- spin_unlock_irq(&mcbsp->lock);
return status;
}
@@ -260,19 +255,17 @@ static ssize_t st_taps_store(struct device *dev,
struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
int val, tmp, status, i = 0;
- spin_lock_irq(&mcbsp->lock);
+ guard(spinlock_irq)(&mcbsp->lock);
memset(st_data->taps, 0, sizeof(st_data->taps));
st_data->nr_taps = 0;
do {
status = sscanf(buf, "%d%n", &val, &tmp);
if (status < 0 || status == 0) {
- size = -EINVAL;
- goto out;
+ return -EINVAL;
}
if (val < -32768 || val > 32767) {
- size = -EINVAL;
- goto out;
+ return -EINVAL;
}
st_data->taps[i++] = val;
buf += tmp;
@@ -283,9 +276,6 @@ static ssize_t st_taps_store(struct device *dev,
st_data->nr_taps = i;
-out:
- spin_unlock_irq(&mcbsp->lock);
-
return size;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling
2026-05-08 10:38 [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers phucduc.bui
` (5 preceding siblings ...)
2026-05-08 10:38 ` [PATCH 6/7] ASoC: ti: omap-mcbsp-st: " phucduc.bui
@ 2026-05-08 10:38 ` phucduc.bui
2026-05-10 1:35 ` Mark Brown
2026-05-09 12:28 ` [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers Jarkko Nikula
7 siblings, 1 reply; 12+ messages in thread
From: phucduc.bui @ 2026-05-08 10:38 UTC (permalink / raw)
To: peter.ujfalusi, broonie
Cc: lgirdwood, perex, tiwai, jarkko.nikula, linux-sound, linux-kernel,
linux-omap, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Convert spinlock protected sections to guard()/scoped_guard()
helpers and simplify the cleanup paths, including the
reg_cache lifetime handling in omap_mcbsp_request().
No functional change intended.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/ti/omap-mcbsp.c | 54 +++++++++++++++++----------------------
1 file changed, 24 insertions(+), 30 deletions(-)
diff --git a/sound/soc/ti/omap-mcbsp.c b/sound/soc/ti/omap-mcbsp.c
index 411970399271..d82fef629867 100644
--- a/sound/soc/ti/omap-mcbsp.c
+++ b/sound/soc/ti/omap-mcbsp.c
@@ -290,23 +290,22 @@ static u16 omap_mcbsp_get_rx_delay(struct omap_mcbsp *mcbsp)
static int omap_mcbsp_request(struct omap_mcbsp *mcbsp)
{
- void *reg_cache;
+ void *reg_cache __free(kfree) = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL);
int err;
- reg_cache = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL);
if (!reg_cache)
return -ENOMEM;
- spin_lock(&mcbsp->lock);
- if (!mcbsp->free) {
- dev_err(mcbsp->dev, "McBSP%d is currently in use\n", mcbsp->id);
- err = -EBUSY;
- goto err_kfree;
- }
+ scoped_guard(spinlock, &mcbsp->lock) {
+ if (!mcbsp->free) {
+ dev_err(mcbsp->dev, "McBSP%d is currently in use\n", mcbsp->id);
+ return -EBUSY;
+ }
- mcbsp->free = false;
- mcbsp->reg_cache = reg_cache;
- spin_unlock(&mcbsp->lock);
+ mcbsp->free = false;
+ mcbsp->reg_cache = reg_cache;
+ reg_cache = NULL;
+ }
if(mcbsp->pdata->ops && mcbsp->pdata->ops->request)
mcbsp->pdata->ops->request(mcbsp->id - 1);
@@ -352,12 +351,11 @@ static int omap_mcbsp_request(struct omap_mcbsp *mcbsp)
if (mcbsp->pdata->has_wakeup)
MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
- spin_lock(&mcbsp->lock);
- mcbsp->free = true;
- mcbsp->reg_cache = NULL;
-err_kfree:
- spin_unlock(&mcbsp->lock);
- kfree(reg_cache);
+ scoped_guard(spinlock, &mcbsp->lock) {
+ reg_cache = mcbsp->reg_cache;
+ mcbsp->free = true;
+ mcbsp->reg_cache = NULL;
+ }
return err;
}
@@ -395,13 +393,13 @@ static void omap_mcbsp_free(struct omap_mcbsp *mcbsp)
if (!mcbsp_omap1())
omap2_mcbsp_set_clks_src(mcbsp, MCBSP_CLKS_PRCM_SRC);
- spin_lock(&mcbsp->lock);
- if (mcbsp->free)
- dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id);
- else
- mcbsp->free = true;
- mcbsp->reg_cache = NULL;
- spin_unlock(&mcbsp->lock);
+ scoped_guard(spinlock, &mcbsp->lock) {
+ if (mcbsp->free)
+ dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id);
+ else
+ mcbsp->free = true;
+ mcbsp->reg_cache = NULL;
+ }
kfree(reg_cache);
}
@@ -581,16 +579,12 @@ static ssize_t dma_op_mode_store(struct device *dev,
if (i < 0)
return i;
- spin_lock_irq(&mcbsp->lock);
+ guard(spinlock_irq)(&mcbsp->lock);
if (!mcbsp->free) {
- size = -EBUSY;
- goto unlock;
+ return -EBUSY;
}
mcbsp->dma_op_mode = i;
-unlock:
- spin_unlock_irq(&mcbsp->lock);
-
return size;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 6/7] ASoC: ti: omap-mcbsp-st: Use guard() for spin locks
2026-05-08 10:38 ` [PATCH 6/7] ASoC: ti: omap-mcbsp-st: " phucduc.bui
@ 2026-05-09 12:26 ` Jarkko Nikula
0 siblings, 0 replies; 12+ messages in thread
From: Jarkko Nikula @ 2026-05-09 12:26 UTC (permalink / raw)
To: phucduc.bui, peter.ujfalusi, broonie
Cc: lgirdwood, perex, tiwai, linux-sound, linux-kernel, linux-omap
On 08/05/2026 1:38 pm, phucduc.bui@gmail.com wrote:
> From: bui duc phuc <phucduc.bui@gmail.com>
>
> Clean up the code using guard() for spin locks.
> Merely code refactoring, and no behavior change.
>
> Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
> ---
> sound/soc/ti/omap-mcbsp-st.c | 26 ++++++++------------------
> 1 file changed, 8 insertions(+), 18 deletions(-)
Tested-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers
2026-05-08 10:38 [PATCH 0/7] ASoC: ti: Cleanup locking code using guard() helpers phucduc.bui
` (6 preceding siblings ...)
2026-05-08 10:38 ` [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling phucduc.bui
@ 2026-05-09 12:28 ` Jarkko Nikula
7 siblings, 0 replies; 12+ messages in thread
From: Jarkko Nikula @ 2026-05-09 12:28 UTC (permalink / raw)
To: phucduc.bui, peter.ujfalusi, broonie
Cc: lgirdwood, perex, tiwai, linux-sound, linux-kernel, linux-omap
On 08/05/2026 1:38 pm, phucduc.bui@gmail.com wrote:
> From: bui duc phuc <phucduc.bui@gmail.com>
>
> Hi all,
>
> This series converts mutex and spinlock handling in TI ASoC drivers
> to use guard() helpers.
>
> Most patches are straightforward conversions to guard() helpers.
> Two patches include minor cleanup changes in the process:
>
> omap-dmic: Simplified omap_dmic_dai_startup() by removing the
> temporary return variable and using a direct return path on error.
>
> omap-mcbsp: Modernized omap_mcbsp_request() by using __free(kfree)
> for memory management. This ensures that memory is always freed on
> error paths after the spinlock is released, without needing manual
> goto labels.
>
> No behavior change intended.
For this set + Tested-by tags for the patches 6 and 7:
Acked-by: Jarkko Nikula <jarkko.nikula@bitmer.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling
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
0 siblings, 1 reply; 12+ messages in thread
From: Mark Brown @ 2026-05-10 1:35 UTC (permalink / raw)
To: phucduc.bui
Cc: peter.ujfalusi, lgirdwood, perex, tiwai, jarkko.nikula,
linux-sound, linux-kernel, linux-omap
[-- Attachment #1: Type: text/plain, Size: 583 bytes --]
On Fri, May 08, 2026 at 05:38:37PM +0700, phucduc.bui@gmail.com wrote:
> Convert spinlock protected sections to guard()/scoped_guard()
> helpers and simplify the cleanup paths, including the
> reg_cache lifetime handling in omap_mcbsp_request().
> static int omap_mcbsp_request(struct omap_mcbsp *mcbsp)
> {
> - void *reg_cache;
> + void *reg_cache __free(kfree) = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL);
> + scoped_guard(spinlock, &mcbsp->lock) {
This function now mixes scoped and goto based cleanup which cleanup.h
warns us not to do - are you sure this is a good idea?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling
2026-05-10 1:35 ` Mark Brown
@ 2026-05-11 4:44 ` Bui Duc Phuc
0 siblings, 0 replies; 12+ messages in thread
From: Bui Duc Phuc @ 2026-05-11 4:44 UTC (permalink / raw)
To: Mark Brown
Cc: peter.ujfalusi, lgirdwood, perex, tiwai, jarkko.nikula,
linux-sound, linux-kernel, linux-omap
Hi Mark, Jarkko,
Thank you for testing and for the feedback.
> This function now mixes scoped and goto based cleanup which cleanup.h
> warns us not to do - are you sure this is a good idea?
I also feel that this function is easier to read and understand if it is
left unchanged, without using __free(kfree) and guard.
However, while cleaning up the code and converting the whole TI
folder to use guard, this function became the only remaining one
not using the new style, which felt a bit inconsistent.
That is why I tried converting it as well.
If you think leaving this single function unchanged is not a problem,
then I will prepare a v2 keeping this function as-is without modifying it.
Best regards,
Phuc
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-05-11 4:44 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/7] ASoC: ti: omap-dmic: " phucduc.bui
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox