ASoC: stm: Use guard() for mutex & spin locks
Subsystems (4)
v2 cover ASoC: stm: Use guard() for mutex & spin locks
From: bui duc phuc <[email protected]>
Hi all,
This series converts mutex and spinlock handling in the STM drivers to use guard() helpers.
The changes are code cleanup only and should have no functional impact.
Best regards,
Phuc
Changes in v2:
Replace break statements inside scoped_guard() blocks with return 0 in stm32_i2s trigger handling, since break only exits the implicit scoped_guard loop rather than the function switch block.
bui duc phuc (4):
ASoC: stm: stm32_adfsdm: Use guard() for mutex locks
ASoC: stm: stm32_i2s: Use guard() for spin locks
ASoC: stm: stm32_sai_sub: Use guard() for mutex & spin locks
ASoC: stm: stm32_spdifrx: Use guard() for spin locks
sound/soc/stm/stm32_adfsdm.c | 10 ++---- sound/soc/stm/stm32_i2s.c | 67 ++++++++++++++++------------------- sound/soc/stm/stm32_sai_sub.c | 29 ++++++--------- sound/soc/stm/stm32_spdifrx.c | 44 +++++++++-------------- 4 files changed, 60 insertions(+), 90 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/4 ASoC: stm: stm32_adfsdm: 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/stm/stm32_adfsdm.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
sound/soc/stm/stm32_adfsdm.c +3 -7
@@ -62,12 +62,11 @@ static void stm32_adfsdm_shutdown(struct snd_pcm_substream *substream, {struct stm32_adfsdm_priv *priv =snd_soc_dai_get_drvdata (dai); -mutex_lock (&priv->lock); +guard (mutex)(&priv->lock);if (priv->iio_active) {iio_channel_stop_all_cb (priv->iio_cb); priv->iio_active = false; } -mutex_unlock (&priv->lock); } static int stm32_adfsdm_dai_prepare(struct snd_pcm_substream *substream,
@@ -76,7 +75,7 @@ static int stm32_adfsdm_dai_prepare(struct snd_pcm_substream *substream,struct stm32_adfsdm_priv *priv =snd_soc_dai_get_drvdata (dai);int ret; -mutex_lock (&priv->lock); +guard (mutex)(&priv->lock);if (priv->iio_active) {iio_channel_stop_all_cb (priv->iio_cb); priv->iio_active = false;
@@ -88,7 +87,7 @@ static int stm32_adfsdm_dai_prepare(struct snd_pcm_substream *substream,if (ret <0 ) {dev_err (dai->dev,"%s: Failed to set %d sampling rate\n" , __func__, substream->runtime->rate); - goto out; +return ret; }if (!priv->iio_active) {
@@ -100,9 +99,6 @@ static int stm32_adfsdm_dai_prepare(struct snd_pcm_substream *substream, __func__, ret); } -out: -mutex_unlock (&priv->lock); -return ret; }
Signature · 1 line
2.43.0
PATCH v2 2/4 ASoC: stm: stm32_i2s: 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.
---
Changes in v2:
Replace break statements inside scoped_guard() blocks with return 0 in stm32_i2s trigger handling, since break only exits the implicit scoped_guard loop rather than the function switch block.
sound/soc/stm/stm32_i2s.c | 67 ++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 37 deletions(-)
sound/soc/stm/stm32_i2s.c +30 -37
@@ -615,10 +615,10 @@ static irqreturn_t stm32_i2s_isr(int irq, void *devid)if (flags &I2S_SR_TIFRE )dev_dbg (&pdev->dev,"Frame error\n" ); -spin_lock (&i2s->irq_lock); -if (err && i2s->substream) -snd_pcm_stop_xrun (i2s->substream); -spin_unlock (&i2s->irq_lock); + scoped_guard(spinlock, &i2s->irq_lock) { +if (err && i2s->substream) +snd_pcm_stop_xrun (i2s->substream); + }return IRQ_HANDLED ; }
@@ -905,12 +905,10 @@ static int stm32_i2s_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) {struct stm32_i2s_data *i2s =snd_soc_dai_get_drvdata (cpu_dai); -unsigned long flags;int ret; -spin_lock_irqsave (&i2s->irq_lock, flags); - i2s->substream = substream; -spin_unlock_irqrestore (&i2s->irq_lock, flags); +scoped_guard (spinlock_irqsave, &i2s->irq_lock) + i2s->substream = substream;if ((i2s->fmt &SND_SOC_DAIFMT_FORMAT_MASK ) !=SND_SOC_DAIFMT_DSP_A ) snd_pcm_hw_constraint_single(substream->runtime,
@@ -982,19 +980,19 @@ static int stm32_i2s_trigger(struct snd_pcm_substream *substream, int cmd,regmap_write_bits (i2s->regmap,STM32_I2S_IFCR_REG ,I2S_IFCR_MASK ,I2S_IFCR_MASK ); -spin_lock (&i2s->lock_fd); - i2s->refcount++; -if (playback_flg) { - ier =I2S_IER_UDRIE ; - }else { - ier =I2S_IER_OVRIE ; - -if (STM32_I2S_IS_MASTER (i2s) && i2s->refcount ==1 ) -/* dummy write to gate bus clocks */ -regmap_write (i2s->regmap, -STM32_I2S_TXDR_REG ,0 ); + scoped_guard(spinlock, &i2s->lock_fd) { + i2s->refcount++; +if (playback_flg) { + ier =I2S_IER_UDRIE ; + }else { + ier =I2S_IER_OVRIE ; + +if (STM32_I2S_IS_MASTER (i2s) && i2s->refcount ==1 ) +/* dummy write to gate bus clocks */ +regmap_write (i2s->regmap, +STM32_I2S_TXDR_REG ,0 ); + } } -spin_unlock (&i2s->lock_fd);if (STM32_I2S_IS_SLAVE (i2s)) ier |=I2S_IER_TIFREIE ;
@@ -1016,21 +1014,18 @@ static int stm32_i2s_trigger(struct snd_pcm_substream *substream, int cmd,I2S_IER_OVRIE , (unsigned int)~I2S_IER_OVRIE); -spin_lock (&i2s->lock_fd); - i2s->refcount--; -if (i2s->refcount) { -spin_unlock (&i2s->lock_fd); -break ; - } + scoped_guard(spinlock, &i2s->lock_fd) { + i2s->refcount--; +if (i2s->refcount) +return 0 ; - ret =regmap_update_bits (i2s->regmap,STM32_I2S_CR1_REG , -I2S_CR1_SPE ,0 ); -if (ret <0 ) { -dev_err (cpu_dai->dev,"Error %d disabling I2S\n" , ret); -spin_unlock (&i2s->lock_fd); -return ret; + ret =regmap_update_bits (i2s->regmap,STM32_I2S_CR1_REG , +I2S_CR1_SPE ,0 ); +if (ret <0 ) { +dev_err (cpu_dai->dev,"Error %d disabling I2S\n" , ret); +return ret; + } } -spin_unlock (&i2s->lock_fd); cfg1_mask =I2S_CFG1_RXDMAEN |I2S_CFG1_TXDMAEN ; regmap_update_bits(i2s->regmap, STM32_I2S_CFG1_REG,
@@ -1047,7 +1042,6 @@ static void stm32_i2s_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) {struct stm32_i2s_data *i2s =snd_soc_dai_get_drvdata (cpu_dai); -unsigned long flags;clk_disable_unprepare (i2s->i2sclk);
@@ -1059,9 +1053,8 @@ static void stm32_i2s_shutdown(struct snd_pcm_substream *substream,if (!i2s->i2smclk && i2s->put_i2s_clk_rate) i2s->put_i2s_clk_rate (i2s); -spin_lock_irqsave (&i2s->irq_lock, flags); - i2s->substream =NULL ; -spin_unlock_irqrestore (&i2s->irq_lock, flags); +scoped_guard (spinlock_irqsave, &i2s->irq_lock) + i2s->substream = NULL; }static int stm32_i2s_dai_probe (struct snd_soc_dai *cpu_dai)
Signature · 1 line
2.43.0
PATCH v2 3/4 ASoC: stm: stm32_sai_sub: Use guard() for mutex & spin locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex & spin locks. Merely code refactoring, and no behavior change.
--- sound/soc/stm/stm32_sai_sub.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-)
sound/soc/stm/stm32_sai_sub.c +11 -18
@@ -280,9 +280,8 @@ static int snd_pcm_iec958_get(struct snd_kcontrol *kcontrol, {struct stm32_sai_sub_data *sai =snd_kcontrol_chip (kcontrol); -mutex_lock (&sai->ctrl_lock); +guard (mutex)(&sai->ctrl_lock);memcpy (uctl->value.iec958.status, sai->iec958.status,4 ); -mutex_unlock (&sai->ctrl_lock);return 0 ; }
@@ -292,9 +291,8 @@ static int snd_pcm_iec958_put(struct snd_kcontrol *kcontrol, {struct stm32_sai_sub_data *sai =snd_kcontrol_chip (kcontrol); -mutex_lock (&sai->ctrl_lock); +guard (mutex)(&sai->ctrl_lock);memcpy (sai->iec958.status, uctl->value.iec958.status,4 ); -mutex_unlock (&sai->ctrl_lock);return 0 ; }
@@ -658,10 +656,10 @@ static irqreturn_t stm32_sai_isr(int irq, void *devid) status =SNDRV_PCM_STATE_XRUN ; } -spin_lock (&sai->irq_lock); -if (status !=SNDRV_PCM_STATE_RUNNING && sai->substream) -snd_pcm_stop_xrun (sai->substream); -spin_unlock (&sai->irq_lock); + scoped_guard(spinlock, &sai->irq_lock) { +if (status !=SNDRV_PCM_STATE_RUNNING && sai->substream) +snd_pcm_stop_xrun (sai->substream); + }return IRQ_HANDLED ; }
@@ -894,11 +892,9 @@ static int stm32_sai_startup(struct snd_pcm_substream *substream, {struct stm32_sai_sub_data *sai =snd_soc_dai_get_drvdata (cpu_dai);int imr, cr2, ret; -unsigned long flags; -spin_lock_irqsave (&sai->irq_lock, flags); - sai->substream = substream; -spin_unlock_irqrestore (&sai->irq_lock, flags); +scoped_guard (spinlock_irqsave, &sai->irq_lock) + sai->substream = substream;if (STM_SAI_PROTOCOL_IS_SPDIF (sai)) { snd_pcm_hw_constraint_mask64(substream->runtime,
@@ -1083,7 +1079,7 @@ static void stm32_sai_set_iec958_status(struct stm32_sai_sub_data *sai,return ;/* Force the sample rate according to runtime rate */ -mutex_lock (&sai->ctrl_lock); +guard (mutex)(&sai->ctrl_lock);switch (runtime->rate) {case 22050 : sai->iec958.status[3 ] =IEC958_AES3_CON_FS_22050 ;
@@ -1116,7 +1112,6 @@ static void stm32_sai_set_iec958_status(struct stm32_sai_sub_data *sai, sai->iec958.status[3 ] =IEC958_AES3_CON_FS_NOTID ;break ; } -mutex_unlock (&sai->ctrl_lock); } static int stm32_sai_configure_clock(struct snd_soc_dai *cpu_dai,
@@ -1284,7 +1279,6 @@ static void stm32_sai_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) {struct stm32_sai_sub_data *sai =snd_soc_dai_get_drvdata (cpu_dai); -unsigned long flags;stm32_sai_sub_reg_up (sai,STM_SAI_IMR_REGX ,SAI_XIMR_MASK ,0 );
@@ -1298,9 +1292,8 @@ static void stm32_sai_shutdown(struct snd_pcm_substream *substream,if (!sai->sai_mclk && sai->put_sai_ck_rate) sai->put_sai_ck_rate (sai); -spin_lock_irqsave (&sai->irq_lock, flags); - sai->substream =NULL ; -spin_unlock_irqrestore (&sai->irq_lock, flags); +scoped_guard (spinlock_irqsave, &sai->irq_lock) + sai->substream = NULL; } static int stm32_sai_pcm_new(struct snd_soc_pcm_runtime *rtd,
Signature · 1 line
2.43.0
PATCH v2 4/4 ASoC: stm: stm32_spdifrx: 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/stm/stm32_spdifrx.c | 44 +++++++++++++---------------------- 1 file changed, 16 insertions(+), 28 deletions(-)
sound/soc/stm/stm32_spdifrx.c +16 -28
@@ -322,7 +322,6 @@ static void stm32_spdifrx_dma_ctrl_stop(struct stm32_spdifrx_data *spdifrx)static int stm32_spdifrx_start_sync (struct stm32_spdifrx_data *spdifrx) {int cr, cr_mask, imr, ret; -unsigned long flags;/* Enable IRQs */ imr =SPDIFRX_IMR_IFEIE |SPDIFRX_IMR_SYNCDIE |SPDIFRX_IMR_PERRIE ;
@@ -330,7 +329,7 @@ static int stm32_spdifrx_start_sync(struct stm32_spdifrx_data *spdifrx)if (ret)return ret; -spin_lock_irqsave (&spdifrx->lock, flags); +guard (spinlock_irqsave)(&spdifrx->lock); spdifrx->refcount++;
@@ -365,22 +364,17 @@ static int stm32_spdifrx_start_sync(struct stm32_spdifrx_data *spdifrx) "Failed to start synchronization\n"); } -spin_unlock_irqrestore (&spdifrx->lock, flags); -return ret; }static void stm32_spdifrx_stop (struct stm32_spdifrx_data *spdifrx) {int cr, cr_mask, reg; -unsigned long flags; -spin_lock_irqsave (&spdifrx->lock, flags); +guard (spinlock_irqsave)(&spdifrx->lock); -if (--spdifrx->refcount) { -spin_unlock_irqrestore (&spdifrx->lock, flags); +if (--spdifrx->refcount)return ; - } cr =SPDIFRX_CR_SPDIFENSET (SPDIFRX_SPDIFEN_DISABLE ); cr_mask =SPDIFRX_CR_SPDIFEN_MASK |SPDIFRX_CR_RXDMAEN ;
@@ -396,8 +390,6 @@ static void stm32_spdifrx_stop(struct stm32_spdifrx_data *spdifrx)/* dummy read to clear CSRNE and RXNE in status register */ regmap_read (spdifrx->regmap,STM32_SPDIFRX_DR , ®);regmap_read (spdifrx->regmap,STM32_SPDIFRX_CSR , ®); - -spin_unlock_irqrestore (&spdifrx->lock, flags); } static int stm32_spdifrx_dma_ctrl_register(struct device *dev,
@@ -744,19 +736,19 @@ static irqreturn_t stm32_spdifrx_isr(int irq, void *devid)return IRQ_HANDLED ; } -spin_lock (&spdifrx->irq_lock); -if (spdifrx->substream) -snd_pcm_stop (spdifrx->substream, -SNDRV_PCM_STATE_DISCONNECTED ); -spin_unlock (&spdifrx->irq_lock); + scoped_guard(spinlock, &spdifrx->irq_lock) { +if (spdifrx->substream) +snd_pcm_stop (spdifrx->substream, +SNDRV_PCM_STATE_DISCONNECTED ); + }return IRQ_HANDLED ; } -spin_lock (&spdifrx->irq_lock); -if (err_xrun && spdifrx->substream) -snd_pcm_stop_xrun (spdifrx->substream); -spin_unlock (&spdifrx->irq_lock); + scoped_guard(spinlock, &spdifrx->irq_lock) { +if (err_xrun && spdifrx->substream) +snd_pcm_stop_xrun (spdifrx->substream); + }return IRQ_HANDLED ; }
@@ -765,12 +757,10 @@ static int stm32_spdifrx_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) {struct stm32_spdifrx_data *spdifrx =snd_soc_dai_get_drvdata (cpu_dai); -unsigned long flags;int ret; -spin_lock_irqsave (&spdifrx->irq_lock, flags); - spdifrx->substream = substream; -spin_unlock_irqrestore (&spdifrx->irq_lock, flags); +scoped_guard (spinlock_irqsave, &spdifrx->irq_lock) + spdifrx->substream = substream; ret =clk_prepare_enable (spdifrx->kclk);if (ret)
@@ -846,11 +836,9 @@ static void stm32_spdifrx_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) {struct stm32_spdifrx_data *spdifrx =snd_soc_dai_get_drvdata (cpu_dai); -unsigned long flags; -spin_lock_irqsave (&spdifrx->irq_lock, flags); - spdifrx->substream =NULL ; -spin_unlock_irqrestore (&spdifrx->irq_lock, flags); +scoped_guard (spinlock_irqsave, &spdifrx->irq_lock) + spdifrx->substream = NULL;clk_disable_unprepare (spdifrx->kclk); }
Signature · 1 line
2.43.0
Mark Brown
maintainerQuoted 11 lines · On Fri, 15 May 2026 18:24:54 +0700, [email protected] wrote:
ASoC: stm: Use
guard()for mutex & spin locksFrom: bui duc phuc <[email protected]>
Hi all,
This series converts mutex and spinlock handling in the STM drivers to use
guard()helpers.
The changes are code cleanup only and should have no functional impact.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.2
Thanks!
[1/4] ASoC: stm: stm32_adfsdm: Use guard() for mutex locks
https://git.kernel.org/broonie/sound/c/dabf5b45b18c [2/4] ASoC: stm: stm32_i2s: Use guard() for spin locks https://git.kernel.org/broonie/sound/c/b212cb00168c [3/4] ASoC: stm: stm32_sai_sub: Use guard() for mutex & spin locks https://git.kernel.org/broonie/sound/c/5e54b4c280af [4/4] ASoC: stm: stm32_spdifrx: Use guard() for spin locks https://git.kernel.org/broonie/sound/c/3f0d573c3259
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