Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] ASoC: stm: Use guard() for mutex & spin locks
@ 2026-05-13 10:43 phucduc.bui
  2026-05-13 10:43 ` [PATCH 1/4] ASoC: stm: stm32_adfsdm: Use guard() for mutex locks phucduc.bui
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: phucduc.bui @ 2026-05-13 10:43 UTC (permalink / raw)
  To: Olivier Moysan, Arnaud Pouliquen, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Maxime Coquelin,
	Alexandre Torgue, linux-sound, linux-stm32, linux-arm-kernel,
	linux-kernel, bui duc phuc

From: bui duc phuc <phucduc.bui@gmail.com>

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

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(-)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/4] ASoC: stm: stm32_adfsdm: Use guard() for mutex locks
  2026-05-13 10:43 [PATCH 0/4] ASoC: stm: Use guard() for mutex & spin locks phucduc.bui
@ 2026-05-13 10:43 ` phucduc.bui
  2026-05-13 10:43 ` [PATCH 2/4] ASoC: stm: stm32_i2s: Use guard() for spin locks phucduc.bui
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: phucduc.bui @ 2026-05-13 10:43 UTC (permalink / raw)
  To: Olivier Moysan, Arnaud Pouliquen, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Maxime Coquelin,
	Alexandre Torgue, linux-sound, linux-stm32, linux-arm-kernel,
	linux-kernel, 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/stm/stm32_adfsdm.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/sound/soc/stm/stm32_adfsdm.c b/sound/soc/stm/stm32_adfsdm.c
index 0f6d32814c22..a585cb9fc011 100644
--- a/sound/soc/stm/stm32_adfsdm.c
+++ b/sound/soc/stm/stm32_adfsdm.c
@@ -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;
 }
 
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/4] ASoC: stm: stm32_i2s: Use guard() for spin locks
  2026-05-13 10:43 [PATCH 0/4] ASoC: stm: Use guard() for mutex & spin locks phucduc.bui
  2026-05-13 10:43 ` [PATCH 1/4] ASoC: stm: stm32_adfsdm: Use guard() for mutex locks phucduc.bui
@ 2026-05-13 10:43 ` phucduc.bui
  2026-05-14  1:25   ` Mark Brown
  2026-05-13 10:43 ` [PATCH 3/4] ASoC: stm: stm32_sai_sub: Use guard() for mutex & " phucduc.bui
  2026-05-13 10:43 ` [PATCH 4/4] ASoC: stm: stm32_spdifrx: Use guard() for " phucduc.bui
  3 siblings, 1 reply; 9+ messages in thread
From: phucduc.bui @ 2026-05-13 10:43 UTC (permalink / raw)
  To: Olivier Moysan, Arnaud Pouliquen, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Maxime Coquelin,
	Alexandre Torgue, linux-sound, linux-stm32, linux-arm-kernel,
	linux-kernel, 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/stm/stm32_i2s.c | 67 ++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 37 deletions(-)

diff --git a/sound/soc/stm/stm32_i2s.c b/sound/soc/stm/stm32_i2s.c
index 6ca21780f21d..4fddb7ecd7fd 100644
--- a/sound/soc/stm/stm32_i2s.c
+++ b/sound/soc/stm/stm32_i2s.c
@@ -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)
+				break;
 
-		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)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/4] ASoC: stm: stm32_sai_sub: Use guard() for mutex & spin locks
  2026-05-13 10:43 [PATCH 0/4] ASoC: stm: Use guard() for mutex & spin locks phucduc.bui
  2026-05-13 10:43 ` [PATCH 1/4] ASoC: stm: stm32_adfsdm: Use guard() for mutex locks phucduc.bui
  2026-05-13 10:43 ` [PATCH 2/4] ASoC: stm: stm32_i2s: Use guard() for spin locks phucduc.bui
@ 2026-05-13 10:43 ` phucduc.bui
  2026-05-13 10:43 ` [PATCH 4/4] ASoC: stm: stm32_spdifrx: Use guard() for " phucduc.bui
  3 siblings, 0 replies; 9+ messages in thread
From: phucduc.bui @ 2026-05-13 10:43 UTC (permalink / raw)
  To: Olivier Moysan, Arnaud Pouliquen, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Maxime Coquelin,
	Alexandre Torgue, linux-sound, linux-stm32, linux-arm-kernel,
	linux-kernel, bui duc phuc

From: bui duc phuc <phucduc.bui@gmail.com>

Clean up the code using guard() for mutex & spin locks.
Merely code refactoring, and no behavior change.

Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
 sound/soc/stm/stm32_sai_sub.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c
index 3e82fa90e719..ea9e8bddd63f 100644
--- a/sound/soc/stm/stm32_sai_sub.c
+++ b/sound/soc/stm/stm32_sai_sub.c
@@ -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,
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/4] ASoC: stm: stm32_spdifrx: Use guard() for spin locks
  2026-05-13 10:43 [PATCH 0/4] ASoC: stm: Use guard() for mutex & spin locks phucduc.bui
                   ` (2 preceding siblings ...)
  2026-05-13 10:43 ` [PATCH 3/4] ASoC: stm: stm32_sai_sub: Use guard() for mutex & " phucduc.bui
@ 2026-05-13 10:43 ` phucduc.bui
  3 siblings, 0 replies; 9+ messages in thread
From: phucduc.bui @ 2026-05-13 10:43 UTC (permalink / raw)
  To: Olivier Moysan, Arnaud Pouliquen, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Maxime Coquelin,
	Alexandre Torgue, linux-sound, linux-stm32, linux-arm-kernel,
	linux-kernel, 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/stm/stm32_spdifrx.c | 44 +++++++++++++----------------------
 1 file changed, 16 insertions(+), 28 deletions(-)

diff --git a/sound/soc/stm/stm32_spdifrx.c b/sound/soc/stm/stm32_spdifrx.c
index 57b711c44278..2f83ca989e68 100644
--- a/sound/soc/stm/stm32_spdifrx.c
+++ b/sound/soc/stm/stm32_spdifrx.c
@@ -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, &reg);
 	regmap_read(spdifrx->regmap, STM32_SPDIFRX_CSR, &reg);
-
-	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);
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/4] ASoC: stm: stm32_i2s: Use guard() for spin locks
  2026-05-13 10:43 ` [PATCH 2/4] ASoC: stm: stm32_i2s: Use guard() for spin locks phucduc.bui
@ 2026-05-14  1:25   ` Mark Brown
  2026-05-14 10:33     ` Bui Duc Phuc
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2026-05-14  1:25 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Olivier Moysan, Arnaud Pouliquen, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Maxime Coquelin, Alexandre Torgue, linux-sound,
	linux-stm32, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 644 bytes --]

On Wed, May 13, 2026 at 05:43:27PM +0700, phucduc.bui@gmail.com wrote:

> @@ -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)
> +				break;

How does scoped_guard interact with break statements - does this still
apply to the switch?  I've not looked at how they're implemented...

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/4] ASoC: stm: stm32_i2s: Use guard() for spin locks
  2026-05-14  1:25   ` Mark Brown
@ 2026-05-14 10:33     ` Bui Duc Phuc
  2026-05-15  1:58       ` Mark Brown
  0 siblings, 1 reply; 9+ messages in thread
From: Bui Duc Phuc @ 2026-05-14 10:33 UTC (permalink / raw)
  To: Mark Brown
  Cc: Olivier Moysan, Arnaud Pouliquen, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Maxime Coquelin, Alexandre Torgue, linux-sound,
	linux-stm32, linux-arm-kernel, linux-kernel

Hi Mark,

On Thu, May 14, 2026 at 8:25 AM Mark Brown <broonie@kernel.org> wrote:
> How does scoped_guard interact with break statements - does this still
> apply to the switch?  I've not looked at how they're implemented...


I checked the scoped_guard macro implementation...
and You're right the break statement inside scoped_guard only exits
the guard's implicit loop, which is not what I intended.

Since there are no further statements after the switch block in this
function, I will replace the break with return 0 to correctly exit
the function.

I'll send a v2 of the whole series with this fix.
Would that work for you?

Best regard,
Phuc


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/4] ASoC: stm: stm32_i2s: Use guard() for spin locks
  2026-05-14 10:33     ` Bui Duc Phuc
@ 2026-05-15  1:58       ` Mark Brown
  2026-05-15  4:48         ` Bui Duc Phuc
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2026-05-15  1:58 UTC (permalink / raw)
  To: Bui Duc Phuc
  Cc: Olivier Moysan, Arnaud Pouliquen, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Maxime Coquelin, Alexandre Torgue, linux-sound,
	linux-stm32, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 148 bytes --]

On Thu, May 14, 2026 at 05:33:17PM +0700, Bui Duc Phuc wrote:

> I'll send a v2 of the whole series with this fix.
> Would that work for you?

Yes.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/4] ASoC: stm: stm32_i2s: Use guard() for spin locks
  2026-05-15  1:58       ` Mark Brown
@ 2026-05-15  4:48         ` Bui Duc Phuc
  0 siblings, 0 replies; 9+ messages in thread
From: Bui Duc Phuc @ 2026-05-15  4:48 UTC (permalink / raw)
  To: Mark Brown
  Cc: Olivier Moysan, Arnaud Pouliquen, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Maxime Coquelin, Alexandre Torgue, linux-sound,
	linux-stm32, linux-arm-kernel, linux-kernel

Hi,


> > I'll send a v2 of the whole series with this fix.
> > Would that work for you?
>
> Yes.

Thank you for the confirmation.
By the way, I have an architectural question that came up during my cleanup...

I noticed that the STM drivers currently manage clk_prepare_enable()/
clk_disable_unprepare() directly from the dai_startup()/shutdown() paths.

After looking through various vendor audio drivers, I noticed that
PM/clock handling styles still vary quite a lot between implementations.

For example:

some Intel drivers enable clocks during dai_link init.

Samsung separates bus/interface clocks and operational clocks,
enabling them in different paths such as probe() and set_sysclk()

UX500 and STM enable clocks during DAI startup()/shutdown()

Tegra, Sunxi, and Rockchip often manage clocks through runtime
PM callbacks

From a maintainer perspective, is there generally interest in gradually
converging these drivers toward more modern/common PM patterns,
or is preserving existing hardware-specific sequencing usually preferred
unless there is a concrete issue to solve?

Best regard,
Phuc


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-05-15  4:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-13 10:43 [PATCH 0/4] ASoC: stm: Use guard() for mutex & spin locks phucduc.bui
2026-05-13 10:43 ` [PATCH 1/4] ASoC: stm: stm32_adfsdm: Use guard() for mutex locks phucduc.bui
2026-05-13 10:43 ` [PATCH 2/4] ASoC: stm: stm32_i2s: Use guard() for spin locks phucduc.bui
2026-05-14  1:25   ` Mark Brown
2026-05-14 10:33     ` Bui Duc Phuc
2026-05-15  1:58       ` Mark Brown
2026-05-15  4:48         ` Bui Duc Phuc
2026-05-13 10:43 ` [PATCH 3/4] ASoC: stm: stm32_sai_sub: Use guard() for mutex & " phucduc.bui
2026-05-13 10:43 ` [PATCH 4/4] ASoC: stm: stm32_spdifrx: Use guard() for " phucduc.bui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox