ASoC: ti: Cleanup locking code using guard() helpers
Subsystems (4)
cover ASoC: ti: Cleanup locking code using guard() helpers
From: bui duc phuc <[email protected]>
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(-)
Signature · 1 line
2.43.0
PATCH 1/7 ASoC: ti: j721e-evm: Use guard() for mutex locks
From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/ti/j721e-evm.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
sound/soc/ti/j721e-evm.c +9 -16
@@ -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 = {
Signature · 1 line
2.43.0
PATCH 2/7 ASoC: ti: omap-dmic: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
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.
--- sound/soc/ti/omap-dmic.c | 44 ++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 26 deletions(-)
sound/soc/ti/omap-dmic.c +18 -26
@@ -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);
Signature · 1 line
2.43.0
PATCH 3/7 ASoC: ti: omap-hdmi: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/ti/omap-hdmi.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
sound/soc/ti/omap-hdmi.c +7 -11
@@ -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 = {
Signature · 1 line
2.43.0
PATCH 4/7 ASoC: ti: omap-mcpdm: Use guard() for mutex locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
--- sound/soc/ti/omap-mcpdm.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
sound/soc/ti/omap-mcpdm.c +2 -6
@@ -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,
Signature · 1 line
2.43.0
PATCH 5/7 ASoC: ti: ams-delta: Use guard() for spin locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/soc/ti/ams-delta.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
sound/soc/ti/ams-delta.c +13 -13
@@ -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);
Signature · 1 line
2.43.0
PATCH 6/7 ASoC: ti: omap-mcbsp-st: Use guard() for spin locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
--- sound/soc/ti/omap-mcbsp-st.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)
sound/soc/ti/omap-mcbsp-st.c +8 -18
@@ -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; }
Signature · 1 line
2.43.0
Re: [PATCH 6/7] ASoC: ti: omap-mcbsp-st: Use guard() for spin locks
Quoted 9 lines · On 08/05/2026 1:38 pm, [email protected] wrote:
From: bui duc phuc <[email protected]>
Clean up the code using
guard()for spin locks.
Merely code refactoring, and no behavior change.Signed-off-by bui duc phuc <[email protected]>--- sound/soc/ti/omap-mcbsp-st.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-)
PATCH 7/7 ASoC: ti: omap-mcbsp: Simplify lock and resource handling
In reply to [email protected]From: bui duc phuc <[email protected]>
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.
--- sound/soc/ti/omap-mcbsp.c | 54 +++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 30 deletions(-)
sound/soc/ti/omap-mcbsp.c +24 -30
@@ -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; }
Signature · 1 line
2.43.0
Mark Brown
maintainerRe: [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling
sound/soc/ti/omap-mcbsp.c static u16 omap_mcbsp_get_rx_delay(struct omap_mcbsp *mcbsp) · line 299
Quoted 10 lines · On Fri, May 08, 2026 at 05:38:37PM +0700, [email protected] wrote:
Convert spinlock protected sections to guard()/scoped_guard() helpers and simplify the cleanup paths, including the
reg_cachelifetime handling inomap_mcbsp_request().static int
omap_mcbsp_request(struct omap_mcbsp *mcbsp){sound/soc/ti/omap-mcbsp.c +2
-1-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?
Re: [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling
Hi Mark, Jarkko,
Thank you for testing and for the feedback.
Quoted 2 lines
This function now mixes scoped and goto based cleanup which
cleanup.hwarns 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
Re: [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling
Hi Mark,
Quoted 2 lines
Quoted 2 lines
This function now mixes scoped and goto based cleanup which
cleanup.hwarns us not to do - are you sure this is a good idea?
If you'd prefer to remove all goto jumps from the function, I can prepare an additional patch for that as well.
-------------------------------------------------
sound/soc/ti/omap-mcbsp.c +2 -9
@@ -322,42 +322,40 @@ static int omap_mcbsp_request(struct omap_mcbsp *mcbsp) "McBSP", (void *)mcbsp);if (err !=0 ) {dev_err (mcbsp->dev,"Unable to request IRQ\n" ); - goto err_clk_disable; } }else { err =request_irq (mcbsp->tx_irq, omap_mcbsp_tx_irq_handler,0 ,"McBSP TX" , (void *)mcbsp);if (err !=0 ) {dev_err (mcbsp->dev,"Unable to request TX IRQ\n" ); - goto err_clk_disable; - } - - err =request_irq (mcbsp->rx_irq, omap_mcbsp_rx_irq_handler,0 , -"McBSP RX" , (void *)mcbsp); -if (err !=0 ) { -dev_err (mcbsp->dev,"Unable to request RX IRQ\n" ); - goto err_free_irq; + }else { + err = request_irq(mcbsp->rx_irq,
omap_mcbsp_rx_irq_handler, 0,
+ "McBSP RX", (void *)mcbsp);
+ if (err != 0) {
+ dev_err(mcbsp->dev, "Unable to request
RX IRQ\n");
+ free_irq(mcbsp->tx_irq, (void *)mcbsp);
+ }
}
}- return 0;
-err_free_irq:
- free_irq(mcbsp->tx_irq, (void *)mcbsp);
-err_clk_disable:
- if(mcbsp->pdata->ops && mcbsp->pdata->ops->free)
- mcbsp->pdata->ops->free(mcbsp->id - 1);
+ if (err != 0) {
+ if(mcbsp->pdata->ops && mcbsp->pdata->ops->free)
+ mcbsp->pdata->ops->free(mcbsp->id - 1);
- /* Disable wakeup behavior */
- if (mcbsp->pdata->has_wakeup)
- MCBSP_WRITE(mcbsp, WAKEUPEN, 0); + /* Disable wakeup behavior */ + if (mcbsp->pdata->has_wakeup)
+ MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
- scoped_guard(spinlock, &mcbsp->lock) {
- reg_cache = mcbsp->reg_cache;
- mcbsp->free = true;
- mcbsp->reg_cache = NULL;
+ scoped_guard(spinlock, &mcbsp->lock) {
+ reg_cache = mcbsp->reg_cache;
+ mcbsp->free = true;
+ mcbsp->reg_cache = NULL;
+ }
+
+ return err;
}- return err;
+ return 0;
}
------------------------------------------------
Please let me know if this looks okay to you, and I'll prepare the patch.
Best regards,
Phuc
Mark Brown
maintainerRe: [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling
Quoted 5 lines · Bui Duc Phuc
Quoted 2 lines
Quoted 2 lines
This function now mixes scoped and goto based cleanup which
cleanup.hwarns us not to do - are you sure this is a good idea?If you'd prefer to remove all goto jumps from the function, I can prepare an additional patch for that as well.
That's probably a useful idea.
Re: [PATCH 7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling
Hi,
Quoted 1 line
That's probably a useful idea.
Thanks for the feedback.
I'll prepare and send the patch shortly.
Best regard,
Phuc
Quoted 13 lines · On 08/05/2026 1:38 pm, [email protected] wrote:
From: bui duc phuc <[email protected]>
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.
Quoted 6 lines
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:
Mark Brown
maintainerQuoted 10 lines · On Fri, 08 May 2026 17:38:30 +0700, [email protected] wrote:
ASoC: ti: Cleanup locking code using
guard()helpersFrom: bui duc phuc <[email protected]>
Hi all,
This series converts mutex and spinlock handling in TI ASoC drivers to use
guard()helpers.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.2
Thanks!
[1/7] ASoC: ti: j721e-evm: Use guard() for mutex locks
https://git.kernel.org/broonie/sound/c/6f4cf77320ae [2/7] ASoC: ti: omap-dmic: Use guard() for mutex locks https://git.kernel.org/broonie/sound/c/bc59728f9349 [3/7] ASoC: ti: omap-hdmi: Use guard() for mutex locks https://git.kernel.org/broonie/sound/c/59115f79acd2 [4/7] ASoC: ti: omap-mcpdm: Use guard() for mutex locks https://git.kernel.org/broonie/sound/c/70031e9ad601 [5/7] ASoC: ti: ams-delta: Use guard() for spin locks https://git.kernel.org/broonie/sound/c/a8217778be47 [6/7] ASoC: ti: omap-mcbsp-st: Use guard() for spin locks https://git.kernel.org/broonie/sound/c/d94e794e8294 [7/7] ASoC: ti: omap-mcbsp: Simplify lock and resource handling https://git.kernel.org/broonie/sound/c/822f67bc269d
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark