All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks
@ 2026-06-15  9:38 phucduc.bui
  2026-06-15  9:38 ` [PATCH v2 01/11] ASoC: fsl_asrc: Use guard() for " phucduc.bui
                   ` (10 more replies)
  0 siblings, 11 replies; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, bui duc phuc

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

Hi all,

This series converts mutex and spinlock handling in the FSL sound drivers
to use guard() helpers.
The changes are code cleanup only and should have no functional impact.

Compile tested only.

Changes in v2:
 - mpc5200_psc_ac97: Fix scoped_guard() usage by replacing
   scoped_guard(mutex_lock, ...) with scoped_guard(mutex, ...).
 - Added compile testing for mpc5200_dma and mpc5200_psc_ac97,
   which were not compile-tested in v1.

Best regards,
Phuc


bui duc phuc (11):
  ASoC: fsl_asrc: Use guard() for spin locks
  ASoC: fsl_audmix: Use guard() for spin locks
  ASoC: fsl_easrc: Use guard() for spin locks
  ASoC: fsl_esai: Use guard() for spin locks
  ASoC: fsl_spdif: Use guard() for spin locks
  ASoC: fsl_ssi: Use guard() for mutex locks
  ASoC: fsl_xcvr: Use guard() for spin locks
  ASoC: imx-audio-rpmsg: Use guard() for spin locks
  ASoC: fsl_rpmsg: Use guard() for mutex & spin locks
  ASoC: fsl: mpc5200_dma: Use guard() for spin locks
  ASoC: fsl: mpc5200_psc_ac97: Use guard() for mutex locks

 sound/soc/fsl/fsl_asrc.c         | 10 +----
 sound/soc/fsl/fsl_audmix.c       | 11 ++---
 sound/soc/fsl/fsl_easrc.c        | 36 +++++------------
 sound/soc/fsl/fsl_esai.c         | 16 +++-----
 sound/soc/fsl/fsl_spdif.c        |  8 +---
 sound/soc/fsl/fsl_ssi.c          | 13 ++----
 sound/soc/fsl/fsl_xcvr.c         | 29 ++++++--------
 sound/soc/fsl/imx-audio-rpmsg.c  | 25 ++++++------
 sound/soc/fsl/imx-pcm-rpmsg.c    | 69 ++++++++++++++------------------
 sound/soc/fsl/mpc5200_dma.c      | 56 +++++++++++++-------------
 sound/soc/fsl/mpc5200_psc_ac97.c | 34 ++++++----------
 11 files changed, 121 insertions(+), 186 deletions(-)

-- 
2.43.0


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

* [PATCH v2 01/11] ASoC: fsl_asrc: Use guard() for spin locks
  2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
@ 2026-06-15  9:38 ` phucduc.bui
  2026-06-15  9:51   ` sashiko-bot
  2026-06-15 14:18   ` Frank Li
  2026-06-15  9:38 ` [PATCH v2 02/11] ASoC: fsl_audmix: " phucduc.bui
                   ` (9 subsequent siblings)
  10 siblings, 2 replies; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, 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/fsl/fsl_asrc.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
index 5fda9b647c70..0b28bcfa47fe 100644
--- a/sound/soc/fsl/fsl_asrc.c
+++ b/sound/soc/fsl/fsl_asrc.c
@@ -222,10 +222,9 @@ static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair)
 	enum asrc_pair_index index = ASRC_INVALID_PAIR;
 	struct fsl_asrc *asrc = pair->asrc;
 	struct device *dev = &asrc->pdev->dev;
-	unsigned long lock_flags;
 	int i, ret = 0;
 
-	spin_lock_irqsave(&asrc->lock, lock_flags);
+	guard(spinlock_irqsave)(&asrc->lock);
 
 	for (i = ASRC_PAIR_A; i < ASRC_PAIR_MAX_NUM; i++) {
 		if (asrc->pair[i] != NULL)
@@ -250,8 +249,6 @@ static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair)
 		pair->index = index;
 	}
 
-	spin_unlock_irqrestore(&asrc->lock, lock_flags);
-
 	return ret;
 }
 
@@ -265,19 +262,16 @@ static void fsl_asrc_release_pair(struct fsl_asrc_pair *pair)
 {
 	struct fsl_asrc *asrc = pair->asrc;
 	enum asrc_pair_index index = pair->index;
-	unsigned long lock_flags;
 
 	/* Make sure the pair is disabled */
 	regmap_update_bits(asrc->regmap, REG_ASRCTR,
 			   ASRCTR_ASRCEi_MASK(index), 0);
 
-	spin_lock_irqsave(&asrc->lock, lock_flags);
+	guard(spinlock_irqsave)(&asrc->lock);
 
 	asrc->channel_avail += pair->channels;
 	asrc->pair[index] = NULL;
 	pair->error = 0;
-
-	spin_unlock_irqrestore(&asrc->lock, lock_flags);
 }
 
 /**
-- 
2.43.0



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

* [PATCH v2 02/11] ASoC: fsl_audmix: Use guard() for spin locks
  2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
  2026-06-15  9:38 ` [PATCH v2 01/11] ASoC: fsl_asrc: Use guard() for " phucduc.bui
@ 2026-06-15  9:38 ` phucduc.bui
  2026-06-15 14:30   ` Frank Li
  2026-06-15  9:38 ` [PATCH v2 03/11] ASoC: fsl_easrc: " phucduc.bui
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, 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/fsl/fsl_audmix.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/sound/soc/fsl/fsl_audmix.c b/sound/soc/fsl/fsl_audmix.c
index 40a3b7432174..066239c64037 100644
--- a/sound/soc/fsl/fsl_audmix.c
+++ b/sound/soc/fsl/fsl_audmix.c
@@ -280,7 +280,6 @@ static int fsl_audmix_dai_trigger(struct snd_pcm_substream *substream, int cmd,
 				  struct snd_soc_dai *dai)
 {
 	struct fsl_audmix *priv = snd_soc_dai_get_drvdata(dai);
-	unsigned long lock_flags;
 
 	/* Capture stream shall not be handled */
 	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
@@ -290,16 +289,14 @@ static int fsl_audmix_dai_trigger(struct snd_pcm_substream *substream, int cmd,
 	case SNDRV_PCM_TRIGGER_START:
 	case SNDRV_PCM_TRIGGER_RESUME:
 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-		spin_lock_irqsave(&priv->lock, lock_flags);
-		priv->tdms |= BIT(dai->driver->id);
-		spin_unlock_irqrestore(&priv->lock, lock_flags);
+		scoped_guard(spinlock_irqsave, &priv->lock)
+			priv->tdms |= BIT(dai->driver->id);
 		break;
 	case SNDRV_PCM_TRIGGER_STOP:
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-		spin_lock_irqsave(&priv->lock, lock_flags);
-		priv->tdms &= ~BIT(dai->driver->id);
-		spin_unlock_irqrestore(&priv->lock, lock_flags);
+		scoped_guard(spinlock_irqsave, &priv->lock)
+			priv->tdms &= ~BIT(dai->driver->id);
 		break;
 	default:
 		return -EINVAL;
-- 
2.43.0



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

* [PATCH v2 03/11] ASoC: fsl_easrc: Use guard() for spin locks
  2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
  2026-06-15  9:38 ` [PATCH v2 01/11] ASoC: fsl_asrc: Use guard() for " phucduc.bui
  2026-06-15  9:38 ` [PATCH v2 02/11] ASoC: fsl_audmix: " phucduc.bui
@ 2026-06-15  9:38 ` phucduc.bui
  2026-06-15  9:48   ` sashiko-bot
  2026-06-15 14:24   ` Frank Li
  2026-06-15  9:38 ` [PATCH v2 04/11] ASoC: fsl_esai: " phucduc.bui
                   ` (7 subsequent siblings)
  10 siblings, 2 replies; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, 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/fsl/fsl_easrc.c | 36 ++++++++++--------------------------
 1 file changed, 10 insertions(+), 26 deletions(-)

diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c
index 114a6c0b6b73..edfd943197a0 100644
--- a/sound/soc/fsl/fsl_easrc.c
+++ b/sound/soc/fsl/fsl_easrc.c
@@ -1025,7 +1025,6 @@ static int fsl_easrc_config_context(struct fsl_asrc *easrc, unsigned int ctx_id)
 	struct fsl_easrc_ctx_priv *ctx_priv;
 	struct fsl_asrc_pair *ctx;
 	struct device *dev;
-	unsigned long lock_flags;
 	int ret;
 
 	if (!easrc)
@@ -1053,9 +1052,8 @@ static int fsl_easrc_config_context(struct fsl_asrc *easrc, unsigned int ctx_id)
 	if (ret)
 		return ret;
 
-	spin_lock_irqsave(&easrc->lock, lock_flags);
-	ret = fsl_easrc_config_slot(easrc, ctx->index);
-	spin_unlock_irqrestore(&easrc->lock, lock_flags);
+	scoped_guard(spinlock_irqsave, &easrc->lock)
+		ret = fsl_easrc_config_slot(easrc, ctx->index);
 	if (ret)
 		return ret;
 
@@ -1301,13 +1299,12 @@ static int fsl_easrc_request_context(int channels, struct fsl_asrc_pair *ctx)
 	enum asrc_pair_index index = ASRC_INVALID_PAIR;
 	struct fsl_asrc *easrc = ctx->asrc;
 	struct device *dev;
-	unsigned long lock_flags;
 	int ret = 0;
 	int i;
 
 	dev = &easrc->pdev->dev;
 
-	spin_lock_irqsave(&easrc->lock, lock_flags);
+	guard(spinlock_irqsave)(&easrc->lock);
 
 	for (i = ASRC_PAIR_A; i < EASRC_CTX_MAX_NUM; i++) {
 		if (easrc->pair[i])
@@ -1331,8 +1328,6 @@ static int fsl_easrc_request_context(int channels, struct fsl_asrc_pair *ctx)
 		easrc->channel_avail -= channels;
 	}
 
-	spin_unlock_irqrestore(&easrc->lock, lock_flags);
-
 	return ret;
 }
 
@@ -1343,7 +1338,6 @@ static int fsl_easrc_request_context(int channels, struct fsl_asrc_pair *ctx)
  */
 static void fsl_easrc_release_context(struct fsl_asrc_pair *ctx)
 {
-	unsigned long lock_flags;
 	struct fsl_asrc *easrc;
 
 	if (!ctx)
@@ -1351,14 +1345,12 @@ static void fsl_easrc_release_context(struct fsl_asrc_pair *ctx)
 
 	easrc = ctx->asrc;
 
-	spin_lock_irqsave(&easrc->lock, lock_flags);
+	guard(spinlock_irqsave)(&easrc->lock);
 
 	fsl_easrc_release_slot(easrc, ctx->index);
 
 	easrc->channel_avail += ctx->channels;
 	easrc->pair[ctx->index] = NULL;
-
-	spin_unlock_irqrestore(&easrc->lock, lock_flags);
 }
 
 /*
@@ -2292,15 +2284,13 @@ static int fsl_easrc_runtime_suspend(struct device *dev)
 {
 	struct fsl_asrc *easrc = dev_get_drvdata(dev);
 	struct fsl_easrc_priv *easrc_priv = easrc->private;
-	unsigned long lock_flags;
 
 	regcache_cache_only(easrc->regmap, true);
 
 	clk_disable_unprepare(easrc->mem_clk);
 
-	spin_lock_irqsave(&easrc->lock, lock_flags);
-	easrc_priv->firmware_loaded = 0;
-	spin_unlock_irqrestore(&easrc->lock, lock_flags);
+	scoped_guard(spinlock_irqsave, &easrc->lock)
+		easrc_priv->firmware_loaded = 0;
 
 	return 0;
 }
@@ -2311,7 +2301,6 @@ static int fsl_easrc_runtime_resume(struct device *dev)
 	struct fsl_easrc_priv *easrc_priv = easrc->private;
 	struct fsl_easrc_ctx_priv *ctx_priv;
 	struct fsl_asrc_pair *ctx;
-	unsigned long lock_flags;
 	int ret;
 	int i;
 
@@ -2323,13 +2312,11 @@ static int fsl_easrc_runtime_resume(struct device *dev)
 	regcache_mark_dirty(easrc->regmap);
 	regcache_sync(easrc->regmap);
 
-	spin_lock_irqsave(&easrc->lock, lock_flags);
-	if (easrc_priv->firmware_loaded) {
-		spin_unlock_irqrestore(&easrc->lock, lock_flags);
-		goto skip_load;
+	scoped_guard(spinlock_irqsave, &easrc->lock) {
+		if (easrc_priv->firmware_loaded)
+			return 0;
+		easrc_priv->firmware_loaded = 1;
 	}
-	easrc_priv->firmware_loaded = 1;
-	spin_unlock_irqrestore(&easrc->lock, lock_flags);
 
 	ret = fsl_easrc_get_firmware(easrc);
 	if (ret) {
@@ -2377,9 +2364,6 @@ static int fsl_easrc_runtime_resume(struct device *dev)
 			goto disable_mem_clk;
 	}
 
-skip_load:
-	return 0;
-
 disable_mem_clk:
 	clk_disable_unprepare(easrc->mem_clk);
 	return ret;
-- 
2.43.0



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

* [PATCH v2 04/11] ASoC: fsl_esai: Use guard() for spin locks
  2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
                   ` (2 preceding siblings ...)
  2026-06-15  9:38 ` [PATCH v2 03/11] ASoC: fsl_easrc: " phucduc.bui
@ 2026-06-15  9:38 ` phucduc.bui
  2026-06-15  9:52   ` sashiko-bot
  2026-06-15 14:15   ` Frank Li
  2026-06-15  9:38 ` [PATCH v2 05/11] ASoC: fsl_spdif: " phucduc.bui
                   ` (6 subsequent siblings)
  10 siblings, 2 replies; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, 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/fsl/fsl_esai.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c
index cde0b0c6c1ef..4a530a6c33f0 100644
--- a/sound/soc/fsl/fsl_esai.c
+++ b/sound/soc/fsl/fsl_esai.c
@@ -709,10 +709,9 @@ static void fsl_esai_hw_reset(struct work_struct *work)
 {
 	struct fsl_esai *esai_priv = container_of(work, struct fsl_esai, work);
 	bool tx = true, rx = false, enabled[2];
-	unsigned long lock_flags;
 	u32 tfcr, rfcr;
 
-	spin_lock_irqsave(&esai_priv->lock, lock_flags);
+	guard(spinlock_irqsave)(&esai_priv->lock);
 	/* Save the registers */
 	regmap_read(esai_priv->regmap, REG_ESAI_TFCR, &tfcr);
 	regmap_read(esai_priv->regmap, REG_ESAI_RFCR, &rfcr);
@@ -750,8 +749,6 @@ static void fsl_esai_hw_reset(struct work_struct *work)
 		fsl_esai_trigger_start(esai_priv, tx);
 	if (enabled[rx])
 		fsl_esai_trigger_start(esai_priv, rx);
-
-	spin_unlock_irqrestore(&esai_priv->lock, lock_flags);
 }
 
 static int fsl_esai_trigger(struct snd_pcm_substream *substream, int cmd,
@@ -759,7 +756,6 @@ static int fsl_esai_trigger(struct snd_pcm_substream *substream, int cmd,
 {
 	struct fsl_esai *esai_priv = snd_soc_dai_get_drvdata(dai);
 	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
-	unsigned long lock_flags;
 
 	esai_priv->channels[tx] = substream->runtime->channels;
 
@@ -767,16 +763,14 @@ static int fsl_esai_trigger(struct snd_pcm_substream *substream, int cmd,
 	case SNDRV_PCM_TRIGGER_START:
 	case SNDRV_PCM_TRIGGER_RESUME:
 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-		spin_lock_irqsave(&esai_priv->lock, lock_flags);
-		fsl_esai_trigger_start(esai_priv, tx);
-		spin_unlock_irqrestore(&esai_priv->lock, lock_flags);
+		scoped_guard(spinlock_irqsave, &esai_priv->lock)
+			fsl_esai_trigger_start(esai_priv, tx);
 		break;
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_STOP:
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-		spin_lock_irqsave(&esai_priv->lock, lock_flags);
-		fsl_esai_trigger_stop(esai_priv, tx);
-		spin_unlock_irqrestore(&esai_priv->lock, lock_flags);
+		scoped_guard(spinlock_irqsave, &esai_priv->lock)
+			fsl_esai_trigger_stop(esai_priv, tx);
 		break;
 	default:
 		return -EINVAL;
-- 
2.43.0


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

* [PATCH v2 05/11] ASoC: fsl_spdif: Use guard() for spin locks
  2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
                   ` (3 preceding siblings ...)
  2026-06-15  9:38 ` [PATCH v2 04/11] ASoC: fsl_esai: " phucduc.bui
@ 2026-06-15  9:38 ` phucduc.bui
  2026-06-15  9:52   ` sashiko-bot
  2026-06-15 14:17   ` Frank Li
  2026-06-15  9:38 ` [PATCH v2 06/11] ASoC: fsl_ssi: Use guard() for mutex locks phucduc.bui
                   ` (5 subsequent siblings)
  10 siblings, 2 replies; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, 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/fsl/fsl_spdif.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/sound/soc/fsl/fsl_spdif.c b/sound/soc/fsl/fsl_spdif.c
index 1b9be85b34c2..ad1206ed9882 100644
--- a/sound/soc/fsl/fsl_spdif.c
+++ b/sound/soc/fsl/fsl_spdif.c
@@ -853,17 +853,15 @@ static int fsl_spdif_subcode_get(struct snd_kcontrol *kcontrol,
 	struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
 	struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
 	struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
-	unsigned long flags;
 	int ret = -EAGAIN;
 
-	spin_lock_irqsave(&ctrl->ctl_lock, flags);
+	guard(spinlock_irqsave)(&ctrl->ctl_lock);
 	if (ctrl->ready_buf) {
 		int idx = (ctrl->ready_buf - 1) * SPDIF_UBITS_SIZE;
 		memcpy(&ucontrol->value.iec958.subcode[0],
 				&ctrl->subcode[idx], SPDIF_UBITS_SIZE);
 		ret = 0;
 	}
-	spin_unlock_irqrestore(&ctrl->ctl_lock, flags);
 
 	return ret;
 }
@@ -885,17 +883,15 @@ static int fsl_spdif_qget(struct snd_kcontrol *kcontrol,
 	struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
 	struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
 	struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
-	unsigned long flags;
 	int ret = -EAGAIN;
 
-	spin_lock_irqsave(&ctrl->ctl_lock, flags);
+	guard(spinlock_irqsave)(&ctrl->ctl_lock);
 	if (ctrl->ready_buf) {
 		int idx = (ctrl->ready_buf - 1) * SPDIF_QSUB_SIZE;
 		memcpy(&ucontrol->value.bytes.data[0],
 				&ctrl->qsub[idx], SPDIF_QSUB_SIZE);
 		ret = 0;
 	}
-	spin_unlock_irqrestore(&ctrl->ctl_lock, flags);
 
 	return ret;
 }
-- 
2.43.0


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

* [PATCH v2 06/11] ASoC: fsl_ssi: Use guard() for mutex locks
  2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
                   ` (4 preceding siblings ...)
  2026-06-15  9:38 ` [PATCH v2 05/11] ASoC: fsl_spdif: " phucduc.bui
@ 2026-06-15  9:38 ` phucduc.bui
  2026-06-15 14:25   ` Frank Li
  2026-06-15  9:38 ` [PATCH v2 07/11] ASoC: fsl_xcvr: Use guard() for spin locks phucduc.bui
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, 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/fsl/fsl_ssi.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index b2e1da1781ae..dc022976c982 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -1218,13 +1218,13 @@ static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
 	if (reg > 0x7f)
 		return;
 
-	mutex_lock(&fsl_ac97_data->ac97_reg_lock);
+	guard(mutex)(&fsl_ac97_data->ac97_reg_lock);
 
 	ret = clk_prepare_enable(fsl_ac97_data->clk);
 	if (ret) {
 		pr_err("ac97 write clk_prepare_enable failed: %d\n",
 			ret);
-		goto ret_unlock;
+		return;
 	}
 
 	lreg = reg <<  12;
@@ -1238,9 +1238,6 @@ static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
 	udelay(100);
 
 	clk_disable_unprepare(fsl_ac97_data->clk);
-
-ret_unlock:
-	mutex_unlock(&fsl_ac97_data->ac97_reg_lock);
 }
 
 static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
@@ -1252,12 +1249,12 @@ static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
 	unsigned int lreg;
 	int ret;
 
-	mutex_lock(&fsl_ac97_data->ac97_reg_lock);
+	guard(mutex)(&fsl_ac97_data->ac97_reg_lock);
 
 	ret = clk_prepare_enable(fsl_ac97_data->clk);
 	if (ret) {
 		pr_err("ac97 read clk_prepare_enable failed: %d\n", ret);
-		goto ret_unlock;
+		return val;
 	}
 
 	lreg = (reg & 0x7f) <<  12;
@@ -1272,8 +1269,6 @@ static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
 
 	clk_disable_unprepare(fsl_ac97_data->clk);
 
-ret_unlock:
-	mutex_unlock(&fsl_ac97_data->ac97_reg_lock);
 	return val;
 }
 
-- 
2.43.0


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

* [PATCH v2 07/11] ASoC: fsl_xcvr: Use guard() for spin locks
  2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
                   ` (5 preceding siblings ...)
  2026-06-15  9:38 ` [PATCH v2 06/11] ASoC: fsl_ssi: Use guard() for mutex locks phucduc.bui
@ 2026-06-15  9:38 ` phucduc.bui
  2026-06-15  9:49   ` sashiko-bot
  2026-06-15 14:19   ` Frank Li
  2026-06-15  9:38 ` [PATCH v2 08/11] ASoC: imx-audio-rpmsg: " phucduc.bui
                   ` (3 subsequent siblings)
  10 siblings, 2 replies; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, 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/fsl/fsl_xcvr.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/sound/soc/fsl/fsl_xcvr.c b/sound/soc/fsl/fsl_xcvr.c
index 6677d3bf36ec..41d100500534 100644
--- a/sound/soc/fsl/fsl_xcvr.c
+++ b/sound/soc/fsl/fsl_xcvr.c
@@ -797,10 +797,9 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
 {
 	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);
 	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
-	unsigned long lock_flags;
 	int ret = 0;
 
-	spin_lock_irqsave(&xcvr->lock, lock_flags);
+	guard(spinlock_irqsave)(&xcvr->lock);
 
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
@@ -812,7 +811,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
 					 FSL_XCVR_EXT_CTRL_DPTH_RESET(tx));
 		if (ret < 0) {
 			dev_err(dai->dev, "Failed to set DPATH RESET: %d\n", ret);
-			goto release_lock;
+			return ret;
 		}
 
 		if (tx) {
@@ -824,7 +823,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
 						   FSL_XCVR_ISR_CMDC_TX_EN);
 				if (ret < 0) {
 					dev_err(dai->dev, "err updating isr %d\n", ret);
-					goto release_lock;
+					return ret;
 				}
 				fallthrough;
 			case FSL_XCVR_MODE_SPDIF:
@@ -833,7 +832,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
 						      FSL_XCVR_TX_DPTH_CTRL_STRT_DATA_TX);
 				if (ret < 0) {
 					dev_err(dai->dev, "Failed to start DATA_TX: %d\n", ret);
-					goto release_lock;
+					return ret;
 				}
 				break;
 			}
@@ -844,14 +843,14 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
 					 FSL_XCVR_EXT_CTRL_DMA_DIS(tx), 0);
 		if (ret < 0) {
 			dev_err(dai->dev, "Failed to enable DMA: %d\n", ret);
-			goto release_lock;
+			return ret;
 		}
 
 		ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_IER0,
 					 FSL_XCVR_IRQ_EARC_ALL, FSL_XCVR_IRQ_EARC_ALL);
 		if (ret < 0) {
 			dev_err(dai->dev, "Error while setting IER0: %d\n", ret);
-			goto release_lock;
+			return ret;
 		}
 
 		/* clear DPATH RESET */
@@ -860,7 +859,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
 					 0);
 		if (ret < 0) {
 			dev_err(dai->dev, "Failed to clear DPATH RESET: %d\n", ret);
-			goto release_lock;
+			return ret;
 		}
 
 		break;
@@ -873,14 +872,14 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
 					 FSL_XCVR_EXT_CTRL_DMA_DIS(tx));
 		if (ret < 0) {
 			dev_err(dai->dev, "Failed to disable DMA: %d\n", ret);
-			goto release_lock;
+			return ret;
 		}
 
 		ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_IER0,
 					 FSL_XCVR_IRQ_EARC_ALL, 0);
 		if (ret < 0) {
 			dev_err(dai->dev, "Failed to clear IER0: %d\n", ret);
-			goto release_lock;
+			return ret;
 		}
 
 		if (tx) {
@@ -891,7 +890,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
 							FSL_XCVR_TX_DPTH_CTRL_STRT_DATA_TX);
 				if (ret < 0) {
 					dev_err(dai->dev, "Failed to stop DATA_TX: %d\n", ret);
-					goto release_lock;
+					return ret;
 				}
 				if (xcvr->soc_data->spdif_only)
 					break;
@@ -905,7 +904,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
 				if (ret < 0) {
 					dev_err(dai->dev,
 						"Err updating ISR %d\n", ret);
-					goto release_lock;
+					return ret;
 				}
 				break;
 			}
@@ -916,8 +915,6 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
 		break;
 	}
 
-release_lock:
-	spin_unlock_irqrestore(&xcvr->lock, lock_flags);
 	return ret;
 }
 
@@ -1448,11 +1445,10 @@ static void reset_rx_work(struct work_struct *work)
 {
 	struct fsl_xcvr *xcvr = container_of(work, struct fsl_xcvr, work_rst);
 	struct device *dev = &xcvr->pdev->dev;
-	unsigned long lock_flags;
 	u32 ext_ctrl;
 
 	dev_dbg(dev, "reset rx path\n");
-	spin_lock_irqsave(&xcvr->lock, lock_flags);
+	guard(spinlock_irqsave)(&xcvr->lock);
 	regmap_read(xcvr->regmap, FSL_XCVR_EXT_CTRL, &ext_ctrl);
 
 	if (!(ext_ctrl & FSL_XCVR_EXT_CTRL_DMA_RD_DIS)) {
@@ -1469,7 +1465,6 @@ static void reset_rx_work(struct work_struct *work)
 				   FSL_XCVR_EXT_CTRL_RX_DPTH_RESET,
 				   0);
 	}
-	spin_unlock_irqrestore(&xcvr->lock, lock_flags);
 }
 
 static irqreturn_t irq0_isr(int irq, void *devid)
-- 
2.43.0


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

* [PATCH v2 08/11] ASoC: imx-audio-rpmsg: Use guard() for spin locks
  2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
                   ` (6 preceding siblings ...)
  2026-06-15  9:38 ` [PATCH v2 07/11] ASoC: fsl_xcvr: Use guard() for spin locks phucduc.bui
@ 2026-06-15  9:38 ` phucduc.bui
  2026-06-15  9:51   ` sashiko-bot
  2026-06-15 14:17   ` Frank Li
  2026-06-15  9:38 ` [PATCH v2 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & " phucduc.bui
                   ` (2 subsequent siblings)
  10 siblings, 2 replies; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, 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/fsl/imx-audio-rpmsg.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/sound/soc/fsl/imx-audio-rpmsg.c b/sound/soc/fsl/imx-audio-rpmsg.c
index 38aafb8954c7..b55dfbdb4502 100644
--- a/sound/soc/fsl/imx-audio-rpmsg.c
+++ b/sound/soc/fsl/imx-audio-rpmsg.c
@@ -22,7 +22,6 @@ static int imx_audio_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
 	struct rpmsg_r_msg *r_msg = (struct rpmsg_r_msg *)data;
 	struct rpmsg_info *info;
 	struct rpmsg_msg *msg;
-	unsigned long flags;
 
 	if (!rpmsg->rpmsg_pdev)
 		return 0;
@@ -37,21 +36,21 @@ static int imx_audio_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
 		/* TYPE C is notification from M core */
 		switch (r_msg->header.cmd) {
 		case TX_PERIOD_DONE:
-			spin_lock_irqsave(&info->lock[TX], flags);
-			msg = &info->msg[TX_PERIOD_DONE + MSG_TYPE_A_NUM];
-			msg->r_msg.param.buffer_tail =
-						r_msg->param.buffer_tail;
-			msg->r_msg.param.buffer_tail %= info->num_period[TX];
-			spin_unlock_irqrestore(&info->lock[TX], flags);
+			scoped_guard(spinlock_irqsave, &info->lock[TX]) {
+				msg = &info->msg[TX_PERIOD_DONE + MSG_TYPE_A_NUM];
+				msg->r_msg.param.buffer_tail =
+							r_msg->param.buffer_tail;
+				msg->r_msg.param.buffer_tail %= info->num_period[TX];
+			}
 			info->callback[TX](info->callback_param[TX]);
 			break;
 		case RX_PERIOD_DONE:
-			spin_lock_irqsave(&info->lock[RX], flags);
-			msg = &info->msg[RX_PERIOD_DONE + MSG_TYPE_A_NUM];
-			msg->r_msg.param.buffer_tail =
-						r_msg->param.buffer_tail;
-			msg->r_msg.param.buffer_tail %= info->num_period[1];
-			spin_unlock_irqrestore(&info->lock[RX], flags);
+			scoped_guard(spinlock_irqsave, &info->lock[RX]) {
+				msg = &info->msg[RX_PERIOD_DONE + MSG_TYPE_A_NUM];
+				msg->r_msg.param.buffer_tail =
+							r_msg->param.buffer_tail;
+				msg->r_msg.param.buffer_tail %= info->num_period[1];
+			}
 			info->callback[RX](info->callback_param[RX]);
 			break;
 		default:
-- 
2.43.0


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

* [PATCH v2 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & spin locks
  2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
                   ` (7 preceding siblings ...)
  2026-06-15  9:38 ` [PATCH v2 08/11] ASoC: imx-audio-rpmsg: " phucduc.bui
@ 2026-06-15  9:38 ` phucduc.bui
  2026-06-15  9:59   ` sashiko-bot
  2026-06-15 14:12   ` Frank Li
  2026-06-15  9:38 ` [PATCH v2 10/11] ASoC: fsl: mpc5200_dma: Use guard() for " phucduc.bui
  2026-06-15  9:38 ` [PATCH v2 11/11] ASoC: fsl: mpc5200_psc_ac97: Use guard() for mutex locks phucduc.bui
  10 siblings, 2 replies; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, 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/fsl/imx-pcm-rpmsg.c | 69 +++++++++++++++--------------------
 1 file changed, 30 insertions(+), 39 deletions(-)

diff --git a/sound/soc/fsl/imx-pcm-rpmsg.c b/sound/soc/fsl/imx-pcm-rpmsg.c
index 031e5272215d..7210393dfa5d 100644
--- a/sound/soc/fsl/imx-pcm-rpmsg.c
+++ b/sound/soc/fsl/imx-pcm-rpmsg.c
@@ -39,10 +39,9 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg,
 	struct rpmsg_device *rpdev = info->rpdev;
 	int ret = 0;
 
-	mutex_lock(&info->msg_lock);
+	guard(mutex)(&info->msg_lock);
 	if (!rpdev) {
 		dev_err(info->dev, "rpmsg channel not ready\n");
-		mutex_unlock(&info->msg_lock);
 		return -EINVAL;
 	}
 
@@ -55,15 +54,12 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg,
 			 sizeof(struct rpmsg_s_msg));
 	if (ret) {
 		dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
-		mutex_unlock(&info->msg_lock);
 		return ret;
 	}
 
 	/* No receive msg for TYPE_C command */
-	if (msg->s_msg.header.type == MSG_TYPE_C) {
-		mutex_unlock(&info->msg_lock);
+	if (msg->s_msg.header.type == MSG_TYPE_C)
 		return 0;
-	}
 
 	/* wait response from rpmsg */
 	ret = wait_for_completion_timeout(&info->cmd_complete,
@@ -71,7 +67,6 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg,
 	if (!ret) {
 		dev_err(&rpdev->dev, "rpmsg_send cmd %d timeout!\n",
 			msg->s_msg.header.cmd);
-		mutex_unlock(&info->msg_lock);
 		return -ETIMEDOUT;
 	}
 
@@ -100,8 +95,6 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg,
 	dev_dbg(&rpdev->dev, "cmd:%d, resp %d\n", msg->s_msg.header.cmd,
 		info->r_msg.param.resp);
 
-	mutex_unlock(&info->msg_lock);
-
 	return 0;
 }
 
@@ -109,14 +102,13 @@ static int imx_rpmsg_insert_workqueue(struct snd_pcm_substream *substream,
 				      struct rpmsg_msg *msg,
 				      struct rpmsg_info *info)
 {
-	unsigned long flags;
 	int ret = 0;
 
 	/*
 	 * Queue the work to workqueue.
 	 * If the queue is full, drop the message.
 	 */
-	spin_lock_irqsave(&info->wq_lock, flags);
+	guard(spinlock_irqsave)(&info->wq_lock);
 	if (info->work_write_index != info->work_read_index) {
 		int index = info->work_write_index;
 
@@ -130,7 +122,6 @@ static int imx_rpmsg_insert_workqueue(struct snd_pcm_substream *substream,
 		info->msg_drop_count[substream->stream]++;
 		ret = -EPIPE;
 	}
-	spin_unlock_irqrestore(&info->wq_lock, flags);
 
 	return ret;
 }
@@ -523,7 +514,6 @@ static int imx_rpmsg_pcm_ack(struct snd_soc_component *component,
 	snd_pcm_sframes_t avail;
 	struct timer_list *timer;
 	struct rpmsg_msg *msg;
-	unsigned long flags;
 	int buffer_tail = 0;
 	int written_num;
 
@@ -553,11 +543,11 @@ static int imx_rpmsg_pcm_ack(struct snd_soc_component *component,
 		msg->s_msg.param.buffer_tail = buffer_tail;
 
 		/* The notification message is updated to latest */
-		spin_lock_irqsave(&info->lock[substream->stream], flags);
-		memcpy(&info->notify[substream->stream], msg,
-		       sizeof(struct rpmsg_s_msg));
-		info->notify_updated[substream->stream] = true;
-		spin_unlock_irqrestore(&info->lock[substream->stream], flags);
+		scoped_guard(spinlock_irqsave, &info->lock[substream->stream]) {
+			memcpy(&info->notify[substream->stream], msg,
+			       sizeof(struct rpmsg_s_msg));
+			info->notify_updated[substream->stream] = true;
+		}
 
 		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 			avail = snd_pcm_playback_hw_avail(runtime);
@@ -640,7 +630,7 @@ static void imx_rpmsg_pcm_work(struct work_struct *work)
 	bool is_notification = false;
 	struct rpmsg_info *info;
 	struct rpmsg_msg msg;
-	unsigned long flags;
+	bool updated;
 
 	work_of_rpmsg = container_of(work, struct work_of_rpmsg, work);
 	info = work_of_rpmsg->info;
@@ -651,25 +641,26 @@ static void imx_rpmsg_pcm_work(struct work_struct *work)
 	 * enough data in M core side, need to let M core know
 	 * data is updated immediately.
 	 */
-	spin_lock_irqsave(&info->lock[TX], flags);
-	if (info->notify_updated[TX]) {
-		memcpy(&msg, &info->notify[TX], sizeof(struct rpmsg_s_msg));
-		info->notify_updated[TX] = false;
-		spin_unlock_irqrestore(&info->lock[TX], flags);
-		info->send_message(&msg, info);
-	} else {
-		spin_unlock_irqrestore(&info->lock[TX], flags);
+	scoped_guard(spinlock_irqsave, &info->lock[TX]) {
+		updated = info->notify_updated[TX];
+		if (updated) {
+			memcpy(&msg, &info->notify[TX], sizeof(struct rpmsg_s_msg));
+			info->notify_updated[TX] = false;
+		}
 	}
-
-	spin_lock_irqsave(&info->lock[RX], flags);
-	if (info->notify_updated[RX]) {
-		memcpy(&msg, &info->notify[RX], sizeof(struct rpmsg_s_msg));
-		info->notify_updated[RX] = false;
-		spin_unlock_irqrestore(&info->lock[RX], flags);
+	if (updated)
 		info->send_message(&msg, info);
-	} else {
-		spin_unlock_irqrestore(&info->lock[RX], flags);
+
+	scoped_guard(spinlock_irqsave, &info->lock[RX]) {
+		updated = info->notify_updated[RX];
+		if (updated) {
+			memcpy(&msg, &info->notify[RX], sizeof(struct rpmsg_s_msg));
+			info->notify_updated[RX] = false;
+		}
 	}
+	if (updated)
+		info->send_message(&msg, info);
+
 
 	/* Skip the notification message for it has been processed above */
 	if (work_of_rpmsg->msg.s_msg.header.type == MSG_TYPE_C &&
@@ -681,10 +672,10 @@ static void imx_rpmsg_pcm_work(struct work_struct *work)
 		info->send_message(&work_of_rpmsg->msg, info);
 
 	/* update read index */
-	spin_lock_irqsave(&info->wq_lock, flags);
-	info->work_read_index++;
-	info->work_read_index %= WORK_MAX_NUM;
-	spin_unlock_irqrestore(&info->wq_lock, flags);
+	scoped_guard(spinlock_irqsave, &info->wq_lock) {
+		info->work_read_index++;
+		info->work_read_index %= WORK_MAX_NUM;
+	}
 }
 
 static int imx_rpmsg_pcm_probe(struct platform_device *pdev)
-- 
2.43.0


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

* [PATCH v2 10/11] ASoC: fsl: mpc5200_dma: Use guard() for spin locks
  2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
                   ` (8 preceding siblings ...)
  2026-06-15  9:38 ` [PATCH v2 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & " phucduc.bui
@ 2026-06-15  9:38 ` phucduc.bui
  2026-06-15  9:57   ` sashiko-bot
  2026-06-15 14:14   ` Frank Li
  2026-06-15  9:38 ` [PATCH v2 11/11] ASoC: fsl: mpc5200_psc_ac97: Use guard() for mutex locks phucduc.bui
  10 siblings, 2 replies; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, 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/fsl/mpc5200_dma.c | 56 ++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/sound/soc/fsl/mpc5200_dma.c b/sound/soc/fsl/mpc5200_dma.c
index 56e2cf2f727b..bfedb2dea0b3 100644
--- a/sound/soc/fsl/mpc5200_dma.c
+++ b/sound/soc/fsl/mpc5200_dma.c
@@ -77,18 +77,20 @@ static irqreturn_t psc_dma_bcom_irq(int irq, void *_psc_dma_stream)
 {
 	struct psc_dma_stream *s = _psc_dma_stream;
 
-	spin_lock(&s->psc_dma->lock);
-	/* For each finished period, dequeue the completed period buffer
-	 * and enqueue a new one in it's place. */
-	while (bcom_buffer_done(s->bcom_task)) {
-		bcom_retrieve_buffer(s->bcom_task, NULL, NULL);
+	scoped_guard(spinlock, &s->psc_dma->lock) {
+		/*
+		 * For each finished period, dequeue the completed period buffer
+		 * and enqueue a new one in its place
+		 */
+		while (bcom_buffer_done(s->bcom_task)) {
+			bcom_retrieve_buffer(s->bcom_task, NULL, NULL);
 
-		s->period_current = (s->period_current+1) % s->runtime->periods;
-		s->period_count++;
+			s->period_current = (s->period_current+1) % s->runtime->periods;
+			s->period_count++;
 
-		psc_dma_bcom_enqueue_next_buffer(s);
+			psc_dma_bcom_enqueue_next_buffer(s);
+		}
 	}
-	spin_unlock(&s->psc_dma->lock);
 
 	/* If the stream is active, then also inform the PCM middle layer
 	 * of the period finished event. */
@@ -116,7 +118,6 @@ static int psc_dma_trigger(struct snd_soc_component *component,
 	struct psc_dma_stream *s = to_psc_dma_stream(substream, psc_dma);
 	struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
 	u16 imr;
-	unsigned long flags;
 	int i;
 
 	switch (cmd) {
@@ -135,19 +136,18 @@ static int psc_dma_trigger(struct snd_soc_component *component,
 		/* Fill up the bestcomm bd queue and enable DMA.
 		 * This will begin filling the PSC's fifo.
 		 */
-		spin_lock_irqsave(&psc_dma->lock, flags);
-
-		if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
-			bcom_gen_bd_rx_reset(s->bcom_task);
-		else
-			bcom_gen_bd_tx_reset(s->bcom_task);
+		scoped_guard(spinlock_irqsave, &psc_dma->lock) {
+			if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
+				bcom_gen_bd_rx_reset(s->bcom_task);
+			else
+				bcom_gen_bd_tx_reset(s->bcom_task);
 
-		for (i = 0; i < runtime->periods; i++)
-			if (!bcom_queue_full(s->bcom_task))
-				psc_dma_bcom_enqueue_next_buffer(s);
+			for (i = 0; i < runtime->periods; i++)
+				if (!bcom_queue_full(s->bcom_task))
+					psc_dma_bcom_enqueue_next_buffer(s);
 
-		bcom_enable(s->bcom_task);
-		spin_unlock_irqrestore(&psc_dma->lock, flags);
+			bcom_enable(s->bcom_task);
+		}
 
 		out_8(&regs->command, MPC52xx_PSC_RST_ERR_STAT);
 
@@ -158,13 +158,13 @@ static int psc_dma_trigger(struct snd_soc_component *component,
 			substream->pstr->stream, s->period_count);
 		s->active = 0;
 
-		spin_lock_irqsave(&psc_dma->lock, flags);
-		bcom_disable(s->bcom_task);
-		if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
-			bcom_gen_bd_rx_reset(s->bcom_task);
-		else
-			bcom_gen_bd_tx_reset(s->bcom_task);
-		spin_unlock_irqrestore(&psc_dma->lock, flags);
+		scoped_guard(spinlock_irqsave, &psc_dma->lock) {
+			bcom_disable(s->bcom_task);
+			if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
+				bcom_gen_bd_rx_reset(s->bcom_task);
+			else
+				bcom_gen_bd_tx_reset(s->bcom_task);
+		}
 
 		break;
 
-- 
2.43.0


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

* [PATCH v2 11/11] ASoC: fsl: mpc5200_psc_ac97: Use guard() for mutex locks
  2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
                   ` (9 preceding siblings ...)
  2026-06-15  9:38 ` [PATCH v2 10/11] ASoC: fsl: mpc5200_dma: Use guard() for " phucduc.bui
@ 2026-06-15  9:38 ` phucduc.bui
  2026-06-15 14:26   ` Frank Li
  10 siblings, 1 reply; 31+ messages in thread
From: phucduc.bui @ 2026-06-15  9:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Shengjiu Wang,
	Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen, Sascha Hauer,
	Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev, 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>
---

Changes in v2:
 - psc_ac97_cold_reset(): Fix scoped_guard() usage by replacing
   scoped_guard(mutex_lock, ...) with scoped_guard(mutex, ...).

 sound/soc/fsl/mpc5200_psc_ac97.c | 34 +++++++++++---------------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/sound/soc/fsl/mpc5200_psc_ac97.c b/sound/soc/fsl/mpc5200_psc_ac97.c
index 8554fb690772..d4d9f5b6bc07 100644
--- a/sound/soc/fsl/mpc5200_psc_ac97.c
+++ b/sound/soc/fsl/mpc5200_psc_ac97.c
@@ -31,14 +31,13 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
 	int status;
 	unsigned int val;
 
-	mutex_lock(&psc_dma->mutex);
+	guard(mutex)(&psc_dma->mutex);
 
 	/* Wait for command send status zero = ready */
 	status = spin_event_timeout(!(in_be16(&psc_dma->psc_regs->sr_csr.status) &
 				MPC52xx_PSC_SR_CMDSEND), 100, 0);
 	if (status == 0) {
 		pr_err("timeout on ac97 bus (rdy)\n");
-		mutex_unlock(&psc_dma->mutex);
 		return -ENODEV;
 	}
 
@@ -54,19 +53,16 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
 	if (status == 0) {
 		pr_err("timeout on ac97 read (val) %x\n",
 				in_be16(&psc_dma->psc_regs->sr_csr.status));
-		mutex_unlock(&psc_dma->mutex);
 		return -ENODEV;
 	}
 	/* Get the data */
 	val = in_be32(&psc_dma->psc_regs->ac97_data);
 	if (((val >> 24) & 0x7f) != reg) {
 		pr_err("reg echo error on ac97 read\n");
-		mutex_unlock(&psc_dma->mutex);
 		return -ENODEV;
 	}
 	val = (val >> 8) & 0xffff;
 
-	mutex_unlock(&psc_dma->mutex);
 	return (unsigned short) val;
 }
 
@@ -75,52 +71,46 @@ static void psc_ac97_write(struct snd_ac97 *ac97,
 {
 	int status;
 
-	mutex_lock(&psc_dma->mutex);
+	guard(mutex)(&psc_dma->mutex);
 
 	/* Wait for command status zero = ready */
 	status = spin_event_timeout(!(in_be16(&psc_dma->psc_regs->sr_csr.status) &
 				MPC52xx_PSC_SR_CMDSEND), 100, 0);
 	if (status == 0) {
 		pr_err("timeout on ac97 bus (write)\n");
-		goto out;
+		return;
 	}
 	/* Write data */
 	out_be32(&psc_dma->psc_regs->ac97_cmd,
 			((reg & 0x7f) << 24) | (val << 8));
-
- out:
-	mutex_unlock(&psc_dma->mutex);
 }
 
 static void psc_ac97_warm_reset(struct snd_ac97 *ac97)
 {
 	struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
 
-	mutex_lock(&psc_dma->mutex);
+	guard(mutex)(&psc_dma->mutex);
 
 	out_be32(&regs->sicr, psc_dma->sicr | MPC52xx_PSC_SICR_AWR);
 	udelay(3);
 	out_be32(&regs->sicr, psc_dma->sicr);
-
-	mutex_unlock(&psc_dma->mutex);
 }
 
 static void psc_ac97_cold_reset(struct snd_ac97 *ac97)
 {
 	struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
 
-	mutex_lock(&psc_dma->mutex);
-	dev_dbg(psc_dma->dev, "cold reset\n");
+	scoped_guard(mutex, &psc_dma->mutex) {
+		dev_dbg(psc_dma->dev, "cold reset\n");
 
-	mpc5200_psc_ac97_gpio_reset(psc_dma->id);
+		mpc5200_psc_ac97_gpio_reset(psc_dma->id);
 
-	/* Notify the PSC that a reset has occurred */
-	out_be32(&regs->sicr, psc_dma->sicr | MPC52xx_PSC_SICR_ACRB);
+		/* Notify the PSC that a reset has occurred */
+		out_be32(&regs->sicr, psc_dma->sicr | MPC52xx_PSC_SICR_ACRB);
 
-	/* Re-enable RX and TX */
-	out_8(&regs->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE);
-
-	mutex_unlock(&psc_dma->mutex);
+		/* Re-enable RX and TX */
+		out_8(&regs->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE);
+	}
 
 	usleep_range(1000, 2000);
 	psc_ac97_warm_reset(ac97);
-- 
2.43.0


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

* Re: [PATCH v2 03/11] ASoC: fsl_easrc: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 03/11] ASoC: fsl_easrc: " phucduc.bui
@ 2026-06-15  9:48   ` sashiko-bot
  2026-06-15 14:24   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-06-15  9:48 UTC (permalink / raw)
  To: phucduc.bui; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The patch erroneously removes `return 0;` from the success path in `fsl_easrc_runtime_resume()`, causing it to unconditionally fall through to the error handler and disable the memory clock.
- [Medium] The function `fsl_easrc_runtime_resume` improperly mixes `goto`-based error handling with scope-based cleanup helpers (`scoped_guard`).
--

commit d28002047081c21222edc1134f1efc00e25fe426
Author: bui duc phuc <phucduc.bui@gmail.com>

ASoC: fsl_easrc: Use guard() for spin locks

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

> diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c
> index 114a6c0b6b730..edfd943197a00 100644
> --- a/sound/soc/fsl/fsl_easrc.c
> +++ b/sound/soc/fsl/fsl_easrc.c
[ ... ]
> @@ -2323,13 +2312,11 @@ static int fsl_easrc_runtime_resume(struct device *dev)
>  	regcache_mark_dirty(easrc->regmap);
>  	regcache_sync(easrc->regmap);
>  
> -	spin_lock_irqsave(&easrc->lock, lock_flags);
> -	if (easrc_priv->firmware_loaded) {
> -		spin_unlock_irqrestore(&easrc->lock, lock_flags);
> -		goto skip_load;
> +	scoped_guard(spinlock_irqsave, &easrc->lock) {
> +		if (easrc_priv->firmware_loaded)
> +			return 0;
> +		easrc_priv->firmware_loaded = 1;
>  	}

[Severity: Medium]
Does this code improperly mix goto-based error handling with scope-based
cleanup helpers?

The function fsl_easrc_runtime_resume() now uses scoped_guard() but still
contains goto disable_mem_clk error handling further down.

According to the cleanup subsystem architecture rules, for a given routine,
all resources needing cleanup should be converted to scope-based cleanup, or
none of them should be. Mixing goto and scoped guards can lead to confusing
ownership semantics.

> -	easrc_priv->firmware_loaded = 1;
> -	spin_unlock_irqrestore(&easrc->lock, lock_flags);
>  
>  	ret = fsl_easrc_get_firmware(easrc);
>  	if (ret) {
[ ... ]
> @@ -2377,9 +2364,6 @@ static int fsl_easrc_runtime_resume(struct device *dev)
>  			goto disable_mem_clk;
>  	}
>  
> -skip_load:
> -	return 0;
> -
>  disable_mem_clk:
>  	clk_disable_unprepare(easrc->mem_clk);
>  	return ret;

[Severity: High]
Does removing this return statement cause a normal success path to fall
through to the error handler?

By removing the skip_load label and its return 0 statement, the normal
success path of fsl_easrc_runtime_resume() directly falls through to the
disable_mem_clk block.

This incorrectly disables the memory clock while returning 0 to indicate
success, potentially causing bus faults on subsequent register accesses.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260615093824.115751-1-phucduc.bui@gmail.com?part=3

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

* Re: [PATCH v2 07/11] ASoC: fsl_xcvr: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 07/11] ASoC: fsl_xcvr: Use guard() for spin locks phucduc.bui
@ 2026-06-15  9:49   ` sashiko-bot
  2026-06-15 14:19   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-06-15  9:49 UTC (permalink / raw)
  To: phucduc.bui; +Cc: Frank.Li, imx

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The probe function registers the IRQ handler and ALSA component before initializing the spinlock and workqueue, creating a critical race condition.
- [High] Device removal cancels the work struct before the IRQ is unregistered, permitting a Use-After-Free if an interrupt fires during the teardown phase.
--

commit aee7964df24f937c0fe7fa3afd74a51f848bcd2f
Author: bui duc phuc <phucduc.bui@gmail.com>

ASoC: fsl_xcvr: Use guard() for spin locks

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

> diff --git a/sound/soc/fsl/fsl_xcvr.c b/sound/soc/fsl/fsl_xcvr.c
> index 6677d3bf36ec2..41d100500534f 100644
> --- a/sound/soc/fsl/fsl_xcvr.c
> +++ b/sound/soc/fsl/fsl_xcvr.c
> @@ -797,10 +797,9 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
>  {
>  	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);
>  	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
> -	unsigned long lock_flags;
>  	int ret = 0;
>  
> -	spin_lock_irqsave(&xcvr->lock, lock_flags);
> +	guard(spinlock_irqsave)(&xcvr->lock);

[Severity: High]
This is a pre-existing issue, but since we are modifying the lock usage here,
could the uninitialized lock be acquired if an interrupt fires early or ALSA
binds immediately?

In fsl_xcvr_probe(), the IRQ handler and ALSA component are registered
before the lock and workqueue are initialized:

fsl_xcvr_probe() {
	...
	ret = devm_request_irq(dev, irq, irq0_isr, 0, pdev->name, xcvr);
	...
	ret = devm_snd_soc_register_component(dev, &fsl_xcvr_comp,
					      &fsl_xcvr_dai, 1);
	...
	INIT_WORK(&xcvr->work_rst, reset_rx_work);
	spin_lock_init(&xcvr->lock);
	...
}

If an interrupt fires immediately upon registration, irq0_isr() will invoke
schedule_work() on an uninitialized work struct.

Similarly, if ALSA immediately invokes the stream trigger callbacks upon
component registration, fsl_xcvr_trigger() will attempt to acquire the
uninitialized spinlock.

[ ... ]

> @@ -1448,11 +1445,10 @@ static void reset_rx_work(struct work_struct *work)
>  {
>  	struct fsl_xcvr *xcvr = container_of(work, struct fsl_xcvr, work_rst);
>  	struct device *dev = &xcvr->pdev->dev;
> -	unsigned long lock_flags;
>  	u32 ext_ctrl;
>  
>  	dev_dbg(dev, "reset rx path\n");
> -	spin_lock_irqsave(&xcvr->lock, lock_flags);
> +	guard(spinlock_irqsave)(&xcvr->lock);

[Severity: High]
This is a pre-existing issue, but could there be a use-after-free during
device removal if an interrupt fires after the work struct is cancelled?

The driver manages the IRQ lifetime using devres, which defers the IRQ
unregistration until after fsl_xcvr_remove() returns:

fsl_xcvr_remove() {
	...
	cancel_work_sync(&xcvr->work_rst);
	pm_runtime_disable(&pdev->dev);
}

Because the IRQ is still actively registered at this time, an incoming
interrupt right after cancel_work_sync() completes will cause irq0_isr() to
call schedule_work(&xcvr->work_rst) again.

As the removal sequence proceeds, devres ultimately frees the xcvr struct,
leaving a scheduled work item in the system pointing to freed memory.

When reset_rx_work() subsequently executes, it will dereference the freed
pointer.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260615093824.115751-1-phucduc.bui@gmail.com?part=7

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

* Re: [PATCH v2 01/11] ASoC: fsl_asrc: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 01/11] ASoC: fsl_asrc: Use guard() for " phucduc.bui
@ 2026-06-15  9:51   ` sashiko-bot
  2026-06-15 14:18   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-06-15  9:51 UTC (permalink / raw)
  To: phucduc.bui; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Lockless access to the `asrc->pair` array in `fsl_asrc_isr` can lead to Use-After-Free and reading uninitialized memory.
--

commit 4b6342441bc61476e92408bc85fb134b9ad8e9f7
Author: bui duc phuc <phucduc.bui@gmail.com>

ASoC: fsl_asrc: Use guard() for spin locks

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

> diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
> index 5fda9b647c704..0b28bcfa47fed 100644
> --- a/sound/soc/fsl/fsl_asrc.c
> +++ b/sound/soc/fsl/fsl_asrc.c

[ ... ]

> @@ -265,19 +262,16 @@ static void fsl_asrc_release_pair(struct fsl_asrc_pair *pair)
>  {
>  	struct fsl_asrc *asrc = pair->asrc;
>  	enum asrc_pair_index index = pair->index;
> -	unsigned long lock_flags;
>  
>  	/* Make sure the pair is disabled */
>  	regmap_update_bits(asrc->regmap, REG_ASRCTR,
>  			   ASRCTR_ASRCEi_MASK(index), 0);
>  
> -	spin_lock_irqsave(&asrc->lock, lock_flags);
> +	guard(spinlock_irqsave)(&asrc->lock);
>  
>  	asrc->channel_avail += pair->channels;
>  	asrc->pair[index] = NULL;

[Severity: High]
This isn't a bug introduced by this patch, but can the lockless access to the
asrc->pair array in fsl_asrc_isr() lead to a use-after-free or reading
uninitialized memory?

In fsl_asrc_release_pair(), the pair is disabled and removed via
asrc->pair[index] = NULL under the lock. However, fsl_asrc_isr() iterates
over the asrc->pair array and dereferences its elements locklessly:

sound/soc/fsl/fsl_asrc.c:fsl_asrc_isr() {
    ...
		if (!asrc->pair[index])
			continue;

		if (status & ASRSTR_ATQOL) {
			asrc->pair[index]->error |= ASRC_TASK_Q_OVERLOAD;
    ...
}

Because the ISR does not take asrc->lock, an ISR executing on another CPU can
read the pointer just before it is nullified. ALSA subsequently calls
fsl_asrc_dma_shutdown(), which frees the memory:

sound/soc/fsl/fsl_asrc_dma.c:fsl_asrc_dma_shutdown() {
    ...
	kfree(pair);
    ...
}

Since there is no synchronize_irq() or lock-based synchronization, the
concurrent ISR can proceed to write to pair->error after the memory is freed,
causing a use-after-free in hardirq context.

Additionally, fsl_asrc_request_pair() publishes the newly allocated pair via a
plain store:

		asrc->pair[index] = pair;

Without a memory barrier (like smp_store_release()), the lockless ISR may see
the pointer before the initialization of the pair structure is visible to its
CPU.

>  	pair->error = 0;
> -
> -	spin_unlock_irqrestore(&asrc->lock, lock_flags);
>  }
>  
>  /**

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260615093824.115751-1-phucduc.bui@gmail.com?part=1

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

* Re: [PATCH v2 08/11] ASoC: imx-audio-rpmsg: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 08/11] ASoC: imx-audio-rpmsg: " phucduc.bui
@ 2026-06-15  9:51   ` sashiko-bot
  2026-06-15 14:17   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-06-15  9:51 UTC (permalink / raw)
  To: phucduc.bui; +Cc: Frank.Li, imx

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [High] Processing unexpected or malicious RPMSG messages before the stream or driver is fully initialized triggers a divide-by-zero or NULL pointer dereference.
- [High] Missing length validation on incoming RPMSG messages allows out-of-bounds reads.
- [High] An error pointer in `rpmsg_pdev` can be dereferenced if the platform device registration fails.
--

commit 61d5b2e3f34cf71daf31644fa46cc656a302b3a3
Author: bui duc phuc <phucduc.bui@gmail.com>

ASoC: imx-audio-rpmsg: Use guard() for spin locks
    
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.

> diff --git a/sound/soc/fsl/imx-audio-rpmsg.c b/sound/soc/fsl/imx-audio-rpmsg.c
> index 38aafb8954c76..b55dfbdb45026 100644
> --- a/sound/soc/fsl/imx-audio-rpmsg.c
> +++ b/sound/soc/fsl/imx-audio-rpmsg.c
> @@ -22,7 +22,6 @@ static int imx_audio_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
>  	struct rpmsg_r_msg *r_msg = (struct rpmsg_r_msg *)data;

[Severity: High]
This isn't a bug introduced by this patch, but is it possible for the remote
processor to send a message smaller than sizeof(struct rpmsg_r_msg)?

There does not appear to be any validation of the len parameter before casting
data to a struct pointer and later unconditionally copying
sizeof(struct rpmsg_r_msg) bytes. Could this lead to an out-of-bounds read
if a truncated message is received?

>  	struct rpmsg_info *info;
>  	struct rpmsg_msg *msg;
> -	unsigned long flags;
>  
>  	if (!rpmsg->rpmsg_pdev)
>  		return 0;

[Severity: High]
This is a pre-existing issue, but does this check adequately handle platform
device registration failures?

If platform_device_register_data() fails during probe, it returns an ERR_PTR
which would pass this NULL check. If an incoming message arrives during this
race window, could this lead to an invalid pointer dereference when
platform_get_drvdata() is called below?

[ ... ]
> @@ -37,21 +36,21 @@ static int imx_audio_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
>  		/* TYPE C is notification from M core */
>  		switch (r_msg->header.cmd) {
>  		case TX_PERIOD_DONE:
> -			spin_lock_irqsave(&info->lock[TX], flags);
> -			msg = &info->msg[TX_PERIOD_DONE + MSG_TYPE_A_NUM];
> -			msg->r_msg.param.buffer_tail =
> -						r_msg->param.buffer_tail;
> -			msg->r_msg.param.buffer_tail %= info->num_period[TX];
> -			spin_unlock_irqrestore(&info->lock[TX], flags);
> +			scoped_guard(spinlock_irqsave, &info->lock[TX]) {

[Severity: High]
This is a pre-existing issue, but are we certain that info and its fields
are fully initialized before this callback can be invoked?

The RPMSG endpoint is created in rpmsg_dev_probe() before the driver's own
probe completes. If the remote processor sends a TX_PERIOD_DONE message
immediately upon endpoint creation, could this race cause a NULL pointer
dereference on info->lock if platform_get_drvdata() returned NULL?

> +				msg = &info->msg[TX_PERIOD_DONE + MSG_TYPE_A_NUM];
> +				msg->r_msg.param.buffer_tail =
> +							r_msg->param.buffer_tail;
> +				msg->r_msg.param.buffer_tail %= info->num_period[TX];

[Severity: High]
This is also pre-existing, but if the stream is uninitialized due to the same
race condition mentioned above, could info->num_period[TX] be zero and
trigger a divide-by-zero exception here?

> +			}
>  			info->callback[TX](info->callback_param[TX]);

[Severity: High]
Similarly, as a pre-existing issue, could info->callback[TX] be uninitialized
and lead to a NULL function pointer dereference if the stream is not yet
prepared?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260615093824.115751-1-phucduc.bui@gmail.com?part=8

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

* Re: [PATCH v2 05/11] ASoC: fsl_spdif: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 05/11] ASoC: fsl_spdif: " phucduc.bui
@ 2026-06-15  9:52   ` sashiko-bot
  2026-06-15 14:17   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-06-15  9:52 UTC (permalink / raw)
  To: phucduc.bui; +Cc: Frank.Li, imx

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] A TOCTOU double-fetch vulnerability on `ctrl->ready_buf` allows an out-of-bounds slab read, potentially leaking sensitive kernel heap memory to user-space.
--

commit 77e81df6d58ee7403495ad362c8b579033ed04a6
Author: bui duc phuc <phucduc.bui@gmail.com>

ASoC: fsl_spdif: Use guard() for spin locks

This patch converts the spin lock handling in fsl_spdif_subcode_get() and
fsl_spdif_qget() to use the guard() macro. It refactors the code without
changing its intended behavior.

> diff --git a/sound/soc/fsl/fsl_spdif.c b/sound/soc/fsl/fsl_spdif.c
> index 1b9be85b34c24..ad1206ed98828 100644
> --- a/sound/soc/fsl/fsl_spdif.c
> +++ b/sound/soc/fsl/fsl_spdif.c
> @@ -853,17 +853,15 @@ static int fsl_spdif_subcode_get(struct snd_kcontrol *kcontrol,
[ ... ]
>  	int ret = -EAGAIN;
>  
> -	spin_lock_irqsave(&ctrl->ctl_lock, flags);
> +	guard(spinlock_irqsave)(&ctrl->ctl_lock);
>  	if (ctrl->ready_buf) {
>  		int idx = (ctrl->ready_buf - 1) * SPDIF_UBITS_SIZE;

[Severity: High]
This is a pre-existing issue, but since the compiler can fetch ctrl->ready_buf
twice (once for the if check, and once for the idx calculation), could this
lead to a Time-of-Check to Time-of-Use (TOCTOU) race?

While this code holds ctl_lock to disable local interrupts, it appears
spdif_irq_uq_err() can run on another CPU and zero ready_buf without taking
ctl_lock:

spdif_irq_uq_err() {
    ...
    /* Drop this U/Q buffer */
    ctrl->ready_buf = 0;
}

If ready_buf becomes 0 between the check and the calculation, idx would
evaluate to a negative index. This would cause the subsequent memcpy to read
out of bounds and potentially leak adjacent slab memory to user-space.

Would caching ready_buf in a local variable using READ_ONCE() prevent this?

>  		memcpy(&ucontrol->value.iec958.subcode[0],
>  				&ctrl->subcode[idx], SPDIF_UBITS_SIZE);
>  		ret = 0;
>  	}
[ ... ]
> @@ -885,17 +883,15 @@ static int fsl_spdif_qget(struct snd_kcontrol *kcontrol,
[ ... ]
>  	int ret = -EAGAIN;
>  
> -	spin_lock_irqsave(&ctrl->ctl_lock, flags);
> +	guard(spinlock_irqsave)(&ctrl->ctl_lock);
>  	if (ctrl->ready_buf) {
>  		int idx = (ctrl->ready_buf - 1) * SPDIF_QSUB_SIZE;

[Severity: High]
This is also a pre-existing issue, but does the same double-fetch
vulnerability exist here?

Like the subcode getter above, if ctrl->ready_buf is zeroed by the interrupt
handler after the check, idx becomes a negative offset. This would result in
memcpy reading from the adjacent memory within the struct instead of the
intended qsub array.

>  		memcpy(&ucontrol->value.bytes.data[0],
>  				&ctrl->qsub[idx], SPDIF_QSUB_SIZE);
>  		ret = 0;
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260615093824.115751-1-phucduc.bui@gmail.com?part=5

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

* Re: [PATCH v2 04/11] ASoC: fsl_esai: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 04/11] ASoC: fsl_esai: " phucduc.bui
@ 2026-06-15  9:52   ` sashiko-bot
  2026-06-15 14:15   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-06-15  9:52 UTC (permalink / raw)
  To: phucduc.bui; +Cc: imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Mixing goto-based error handling with scope-based cleanup in fsl_easrc_runtime_resume
--

commit d28002047081c21222edc1134f1efc00e25fe426
Author: bui duc phuc <phucduc.bui@gmail.com>

ASoC: fsl_easrc: Use guard() for spin locks
    
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.

> diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c
> index 114a6c0b6b730..edfd943197a00 100644
> --- a/sound/soc/fsl/fsl_easrc.c
> +++ b/sound/soc/fsl/fsl_easrc.c

[ ... ]

> @@ -2323,13 +2312,11 @@ static int fsl_easrc_runtime_resume(struct device *dev)
>  	regcache_mark_dirty(easrc->regmap);
>  	regcache_sync(easrc->regmap);
>  
> -	spin_lock_irqsave(&easrc->lock, lock_flags);
> -	if (easrc_priv->firmware_loaded) {
> -		spin_unlock_irqrestore(&easrc->lock, lock_flags);
> -		goto skip_load;
> +	scoped_guard(spinlock_irqsave, &easrc->lock) {
> +		if (easrc_priv->firmware_loaded)
> +			return 0;
> +		easrc_priv->firmware_loaded = 1;
>  	}
> -	easrc_priv->firmware_loaded = 1;
> -	spin_unlock_irqrestore(&easrc->lock, lock_flags);
>  
>  	ret = fsl_easrc_get_firmware(easrc);
>  	if (ret) {
> @@ -2377,9 +2364,6 @@ static int fsl_easrc_runtime_resume(struct device *dev)
>  			goto disable_mem_clk;
>  	}

[Severity: Medium]
Is it safe to mix scoped_guard() with the goto disable_mem_clk error path in
this function?

The subsystem guidelines for cleanup helpers (derived from
include/linux/cleanup.h) indicate that usage of goto and scope-based cleanup
should not be mixed in the same function.

Should fsl_easrc_runtime_resume() be converted to use scope-based cleanup for
all resources, or should it avoid using scoped_guard() here to prevent
ownership confusion?

>  
> -skip_load:
> -	return 0;
> -
>  disable_mem_clk:
>  	clk_disable_unprepare(easrc->mem_clk);
>  	return ret;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260615093824.115751-1-phucduc.bui@gmail.com?part=4

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

* Re: [PATCH v2 10/11] ASoC: fsl: mpc5200_dma: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 10/11] ASoC: fsl: mpc5200_dma: Use guard() for " phucduc.bui
@ 2026-06-15  9:57   ` sashiko-bot
  2026-06-15 14:14   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-06-15  9:57 UTC (permalink / raw)
  To: phucduc.bui; +Cc: Frank.Li, imx

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The `psc_dma` structure is freed in `mpc5200_audio_dma_destroy()` before the ALSA components are unregistered, leading to a use-after-free and locking of freed memory if userspace invokes component operations during module unbind.
--

commit d1f00eba902c807bb72ff7810e5332f8b08165b6
Author: bui duc phuc <phucduc.bui@gmail.com>

    ASoC: fsl: mpc5200_dma: Use guard() for spin locks

This commit cleans up the spin lock usage in the mpc5200_dma driver by
converting it to use the scoped_guard() macro.

> diff --git a/sound/soc/fsl/mpc5200_dma.c b/sound/soc/fsl/mpc5200_dma.c
> index 56e2cf2f727ba..bfedb2dea0b32 100644
> --- a/sound/soc/fsl/mpc5200_dma.c
> +++ b/sound/soc/fsl/mpc5200_dma.c
[ ... ]
> @@ -135,19 +136,18 @@ static int psc_dma_trigger(struct snd_soc_component *component,
>  		/* Fill up the bestcomm bd queue and enable DMA.
>  		 * This will begin filling the PSC's fifo.
>  		 */
> -		spin_lock_irqsave(&psc_dma->lock, flags);
> -
> -		if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
> -			bcom_gen_bd_rx_reset(s->bcom_task);
> -		else
> -			bcom_gen_bd_tx_reset(s->bcom_task);
> +		scoped_guard(spinlock_irqsave, &psc_dma->lock) {

[Severity: High]
This isn't a bug introduced by this patch, but could this code race with
module unbind and dereference a freed psc_dma pointer?

During driver removal, the callbacks (like psc_i2s_of_remove) manually call
mpc5200_audio_dma_destroy(), which frees the psc_dma object and clears the
driver data:

sound/soc/fsl/mpc5200_dma.c:mpc5200_audio_dma_destroy() {
    ...
	kfree(psc_dma);
	dev_set_drvdata(&op->dev, NULL);
}

However, the ALSA component is registered via devm_snd_soc_register_component(),
meaning it remains registered and accessible to userspace until the devres
teardown runs after the remove callback returns.

If userspace invokes a PCM operation during this window, ALSA could call
psc_dma_trigger(), which fetches the driver data (now NULL or pointing
to freed memory) and attempts to acquire the lock here using scoped_guard(),
leading to a use-after-free or NULL pointer dereference crash.

> +			if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
> +				bcom_gen_bd_rx_reset(s->bcom_task);
> +			else
> +				bcom_gen_bd_tx_reset(s->bcom_task);
>  
> -		for (i = 0; i < runtime->periods; i++)
> -			if (!bcom_queue_full(s->bcom_task))
> -				psc_dma_bcom_enqueue_next_buffer(s);
> +			for (i = 0; i < runtime->periods; i++)
> +				if (!bcom_queue_full(s->bcom_task))
> +					psc_dma_bcom_enqueue_next_buffer(s);
>  
> -		bcom_enable(s->bcom_task);
> -		spin_unlock_irqrestore(&psc_dma->lock, flags);
> +			bcom_enable(s->bcom_task);
> +		}
>  
>  		out_8(&regs->command, MPC52xx_PSC_RST_ERR_STAT);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260615093824.115751-1-phucduc.bui@gmail.com?part=10

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

* Re: [PATCH v2 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & spin locks
  2026-06-15  9:38 ` [PATCH v2 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & " phucduc.bui
@ 2026-06-15  9:59   ` sashiko-bot
  2026-06-15 14:12   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-06-15  9:59 UTC (permalink / raw)
  To: phucduc.bui; +Cc: Frank.Li, imx

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [High] Non-synchronous timer cancellation (`timer_delete()`) and improper teardown order allow race conditions and use-after-free.
- [High] Unvalidated remote processor command index allows out-of-bounds array write.
- [High] Workqueue destroyed before ALSA component unregistration leads to Use-After-Free.
--

commit fb7a6469268cda085459a69bd6a9d37338ef0a42
Author: bui duc phuc <phucduc.bui@gmail.com>

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

> diff --git a/sound/soc/fsl/imx-pcm-rpmsg.c b/sound/soc/fsl/imx-pcm-rpmsg.c
> index 031e5272215d4..7210393dfa5d9 100644
> --- a/sound/soc/fsl/imx-pcm-rpmsg.c
> +++ b/sound/soc/fsl/imx-pcm-rpmsg.c

[ ... ]

> @@ -71,7 +67,6 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg,
>  	if (!ret) {
>  		dev_err(&rpdev->dev, "rpmsg_send cmd %d timeout!\n",
>  			msg->s_msg.header.cmd);
> -		mutex_unlock(&info->msg_lock);
>  		return -ETIMEDOUT;
>  	}

[Severity: High]
This is a pre-existing issue, but can this out-of-bounds write occur here?

Looking at the code just below this in imx_rpmsg_pcm_send_message():

	memcpy(&msg->r_msg, &info->r_msg, sizeof(struct rpmsg_r_msg));
	memcpy(&info->msg[msg->r_msg.header.cmd].r_msg,
	       &msg->r_msg, sizeof(struct rpmsg_r_msg));

The msg->r_msg.header.cmd field comes from the remote processor and is used
directly as an array index for info->msg. Since cmd is an 8-bit unsigned
integer, and the array bounds are likely smaller, a compromised remote
processor could send a command ID up to 255.

Does this allow an out-of-bounds write that corrupts adjacent heap
structures like the workqueue pointer?

[ ... ]

> @@ -681,10 +672,10 @@ static void imx_rpmsg_pcm_work(struct work_struct *work)
>  		info->send_message(&work_of_rpmsg->msg, info);
>  
>  	/* update read index */
> -	spin_lock_irqsave(&info->wq_lock, flags);
> -	info->work_read_index++;
> -	info->work_read_index %= WORK_MAX_NUM;
> -	spin_unlock_irqrestore(&info->wq_lock, flags);
> +	scoped_guard(spinlock_irqsave, &info->wq_lock) {
> +		info->work_read_index++;
> +		info->work_read_index %= WORK_MAX_NUM;
> +	}
>  }

[Severity: High]
This is a pre-existing issue, but does using timer_delete() instead of
timer_delete_sync() or timer_shutdown_sync() allow the timer callback
to execute after teardown?

In imx_rpmsg_pcm_close() and imx_rpmsg_terminate_all():

	timer_delete(&info->stream_timer[substream->stream].timer);

This non-synchronous deletion means the timer callback might continue
executing concurrently. In imx_rpmsg_pcm_close(), timer_delete() is called
after flush_workqueue(), so a late timer callback could queue new work
after the stream is supposedly closed.

Additionally, imx_rpmsg_pcm_remove() does not appear to stop timers
before devres frees the info structure, potentially leading to a
use-after-free if a timer is still pending.

[Severity: High]
This isn't a bug introduced by this patch, but does the current cleanup
order in imx_rpmsg_pcm_remove() cause a use-after-free?

The driver registers the component using devm_snd_soc_register_component()
in imx_rpmsg_pcm_probe(), which relies on devres for cleanup. However, the
workqueue is explicitly destroyed in imx_rpmsg_pcm_remove():

static void imx_rpmsg_pcm_remove(struct platform_device *pdev)
{
	...
	if (info->rpmsg_wq)
		destroy_workqueue(info->rpmsg_wq);
}

Since devres runs after the remove callback returns, the component
remains active while the workqueue is already destroyed. If a stream
is closed during this window, imx_rpmsg_pcm_close() will call
flush_workqueue(info->rpmsg_wq) on the destroyed workqueue.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260615093824.115751-1-phucduc.bui@gmail.com?part=9

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

* Re: [PATCH v2 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & spin locks
  2026-06-15  9:38 ` [PATCH v2 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & " phucduc.bui
  2026-06-15  9:59   ` sashiko-bot
@ 2026-06-15 14:12   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: Frank Li @ 2026-06-15 14:12 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Shengjiu Wang, Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen,
	Sascha Hauer, Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev

On Mon, Jun 15, 2026 at 04:38:22PM +0700, phucduc.bui@gmail.com wrote:
> 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  sound/soc/fsl/imx-pcm-rpmsg.c | 69 +++++++++++++++--------------------
>  1 file changed, 30 insertions(+), 39 deletions(-)
>
> diff --git a/sound/soc/fsl/imx-pcm-rpmsg.c b/sound/soc/fsl/imx-pcm-rpmsg.c
> index 031e5272215d..7210393dfa5d 100644
> --- a/sound/soc/fsl/imx-pcm-rpmsg.c
> +++ b/sound/soc/fsl/imx-pcm-rpmsg.c
> @@ -39,10 +39,9 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg,
>  	struct rpmsg_device *rpdev = info->rpdev;
>  	int ret = 0;
>
> -	mutex_lock(&info->msg_lock);
> +	guard(mutex)(&info->msg_lock);
>  	if (!rpdev) {
>  		dev_err(info->dev, "rpmsg channel not ready\n");
> -		mutex_unlock(&info->msg_lock);
>  		return -EINVAL;
>  	}
>
> @@ -55,15 +54,12 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg,
>  			 sizeof(struct rpmsg_s_msg));
>  	if (ret) {
>  		dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
> -		mutex_unlock(&info->msg_lock);
>  		return ret;
>  	}
>
>  	/* No receive msg for TYPE_C command */
> -	if (msg->s_msg.header.type == MSG_TYPE_C) {
> -		mutex_unlock(&info->msg_lock);
> +	if (msg->s_msg.header.type == MSG_TYPE_C)
>  		return 0;
> -	}
>
>  	/* wait response from rpmsg */
>  	ret = wait_for_completion_timeout(&info->cmd_complete,
> @@ -71,7 +67,6 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg,
>  	if (!ret) {
>  		dev_err(&rpdev->dev, "rpmsg_send cmd %d timeout!\n",
>  			msg->s_msg.header.cmd);
> -		mutex_unlock(&info->msg_lock);
>  		return -ETIMEDOUT;
>  	}
>
> @@ -100,8 +95,6 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg,
>  	dev_dbg(&rpdev->dev, "cmd:%d, resp %d\n", msg->s_msg.header.cmd,
>  		info->r_msg.param.resp);
>
> -	mutex_unlock(&info->msg_lock);
> -
>  	return 0;
>  }
>
> @@ -109,14 +102,13 @@ static int imx_rpmsg_insert_workqueue(struct snd_pcm_substream *substream,
>  				      struct rpmsg_msg *msg,
>  				      struct rpmsg_info *info)
>  {
> -	unsigned long flags;
>  	int ret = 0;
>
>  	/*
>  	 * Queue the work to workqueue.
>  	 * If the queue is full, drop the message.
>  	 */
> -	spin_lock_irqsave(&info->wq_lock, flags);
> +	guard(spinlock_irqsave)(&info->wq_lock);
>  	if (info->work_write_index != info->work_read_index) {
>  		int index = info->work_write_index;
>
> @@ -130,7 +122,6 @@ static int imx_rpmsg_insert_workqueue(struct snd_pcm_substream *substream,
>  		info->msg_drop_count[substream->stream]++;
>  		ret = -EPIPE;
>  	}
> -	spin_unlock_irqrestore(&info->wq_lock, flags);
>
>  	return ret;
>  }
> @@ -523,7 +514,6 @@ static int imx_rpmsg_pcm_ack(struct snd_soc_component *component,
>  	snd_pcm_sframes_t avail;
>  	struct timer_list *timer;
>  	struct rpmsg_msg *msg;
> -	unsigned long flags;
>  	int buffer_tail = 0;
>  	int written_num;
>
> @@ -553,11 +543,11 @@ static int imx_rpmsg_pcm_ack(struct snd_soc_component *component,
>  		msg->s_msg.param.buffer_tail = buffer_tail;
>
>  		/* The notification message is updated to latest */
> -		spin_lock_irqsave(&info->lock[substream->stream], flags);
> -		memcpy(&info->notify[substream->stream], msg,
> -		       sizeof(struct rpmsg_s_msg));
> -		info->notify_updated[substream->stream] = true;
> -		spin_unlock_irqrestore(&info->lock[substream->stream], flags);
> +		scoped_guard(spinlock_irqsave, &info->lock[substream->stream]) {
> +			memcpy(&info->notify[substream->stream], msg,
> +			       sizeof(struct rpmsg_s_msg));
> +			info->notify_updated[substream->stream] = true;
> +		}
>
>  		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
>  			avail = snd_pcm_playback_hw_avail(runtime);
> @@ -640,7 +630,7 @@ static void imx_rpmsg_pcm_work(struct work_struct *work)
>  	bool is_notification = false;
>  	struct rpmsg_info *info;
>  	struct rpmsg_msg msg;
> -	unsigned long flags;
> +	bool updated;
>
>  	work_of_rpmsg = container_of(work, struct work_of_rpmsg, work);
>  	info = work_of_rpmsg->info;
> @@ -651,25 +641,26 @@ static void imx_rpmsg_pcm_work(struct work_struct *work)
>  	 * enough data in M core side, need to let M core know
>  	 * data is updated immediately.
>  	 */
> -	spin_lock_irqsave(&info->lock[TX], flags);
> -	if (info->notify_updated[TX]) {
> -		memcpy(&msg, &info->notify[TX], sizeof(struct rpmsg_s_msg));
> -		info->notify_updated[TX] = false;
> -		spin_unlock_irqrestore(&info->lock[TX], flags);
> -		info->send_message(&msg, info);
> -	} else {
> -		spin_unlock_irqrestore(&info->lock[TX], flags);
> +	scoped_guard(spinlock_irqsave, &info->lock[TX]) {
> +		updated = info->notify_updated[TX];
> +		if (updated) {
> +			memcpy(&msg, &info->notify[TX], sizeof(struct rpmsg_s_msg));
> +			info->notify_updated[TX] = false;
> +		}
>  	}
> -
> -	spin_lock_irqsave(&info->lock[RX], flags);
> -	if (info->notify_updated[RX]) {
> -		memcpy(&msg, &info->notify[RX], sizeof(struct rpmsg_s_msg));
> -		info->notify_updated[RX] = false;
> -		spin_unlock_irqrestore(&info->lock[RX], flags);
> +	if (updated)
>  		info->send_message(&msg, info);
> -	} else {
> -		spin_unlock_irqrestore(&info->lock[RX], flags);
> +
> +	scoped_guard(spinlock_irqsave, &info->lock[RX]) {
> +		updated = info->notify_updated[RX];
> +		if (updated) {
> +			memcpy(&msg, &info->notify[RX], sizeof(struct rpmsg_s_msg));
> +			info->notify_updated[RX] = false;
> +		}
>  	}
> +	if (updated)
> +		info->send_message(&msg, info);
> +
>
>  	/* Skip the notification message for it has been processed above */
>  	if (work_of_rpmsg->msg.s_msg.header.type == MSG_TYPE_C &&
> @@ -681,10 +672,10 @@ static void imx_rpmsg_pcm_work(struct work_struct *work)
>  		info->send_message(&work_of_rpmsg->msg, info);
>
>  	/* update read index */
> -	spin_lock_irqsave(&info->wq_lock, flags);
> -	info->work_read_index++;
> -	info->work_read_index %= WORK_MAX_NUM;
> -	spin_unlock_irqrestore(&info->wq_lock, flags);
> +	scoped_guard(spinlock_irqsave, &info->wq_lock) {
> +		info->work_read_index++;
> +		info->work_read_index %= WORK_MAX_NUM;
> +	}
>  }
>
>  static int imx_rpmsg_pcm_probe(struct platform_device *pdev)
> --
> 2.43.0
>
>

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

* Re: [PATCH v2 10/11] ASoC: fsl: mpc5200_dma: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 10/11] ASoC: fsl: mpc5200_dma: Use guard() for " phucduc.bui
  2026-06-15  9:57   ` sashiko-bot
@ 2026-06-15 14:14   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: Frank Li @ 2026-06-15 14:14 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Shengjiu Wang, Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen,
	Sascha Hauer, Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev

On Mon, Jun 15, 2026 at 04:38:23PM +0700, 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  sound/soc/fsl/mpc5200_dma.c | 56 ++++++++++++++++++-------------------
>  1 file changed, 28 insertions(+), 28 deletions(-)
>
> diff --git a/sound/soc/fsl/mpc5200_dma.c b/sound/soc/fsl/mpc5200_dma.c
> index 56e2cf2f727b..bfedb2dea0b3 100644
> --- a/sound/soc/fsl/mpc5200_dma.c
> +++ b/sound/soc/fsl/mpc5200_dma.c
> @@ -77,18 +77,20 @@ static irqreturn_t psc_dma_bcom_irq(int irq, void *_psc_dma_stream)
>  {
>  	struct psc_dma_stream *s = _psc_dma_stream;
>
> -	spin_lock(&s->psc_dma->lock);
> -	/* For each finished period, dequeue the completed period buffer
> -	 * and enqueue a new one in it's place. */
> -	while (bcom_buffer_done(s->bcom_task)) {
> -		bcom_retrieve_buffer(s->bcom_task, NULL, NULL);
> +	scoped_guard(spinlock, &s->psc_dma->lock) {
> +		/*
> +		 * For each finished period, dequeue the completed period buffer
> +		 * and enqueue a new one in its place
> +		 */
> +		while (bcom_buffer_done(s->bcom_task)) {
> +			bcom_retrieve_buffer(s->bcom_task, NULL, NULL);
>
> -		s->period_current = (s->period_current+1) % s->runtime->periods;
> -		s->period_count++;
> +			s->period_current = (s->period_current+1) % s->runtime->periods;
> +			s->period_count++;
>
> -		psc_dma_bcom_enqueue_next_buffer(s);
> +			psc_dma_bcom_enqueue_next_buffer(s);
> +		}
>  	}
> -	spin_unlock(&s->psc_dma->lock);
>
>  	/* If the stream is active, then also inform the PCM middle layer
>  	 * of the period finished event. */
> @@ -116,7 +118,6 @@ static int psc_dma_trigger(struct snd_soc_component *component,
>  	struct psc_dma_stream *s = to_psc_dma_stream(substream, psc_dma);
>  	struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
>  	u16 imr;
> -	unsigned long flags;
>  	int i;
>
>  	switch (cmd) {
> @@ -135,19 +136,18 @@ static int psc_dma_trigger(struct snd_soc_component *component,
>  		/* Fill up the bestcomm bd queue and enable DMA.
>  		 * This will begin filling the PSC's fifo.
>  		 */
> -		spin_lock_irqsave(&psc_dma->lock, flags);
> -
> -		if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
> -			bcom_gen_bd_rx_reset(s->bcom_task);
> -		else
> -			bcom_gen_bd_tx_reset(s->bcom_task);
> +		scoped_guard(spinlock_irqsave, &psc_dma->lock) {
> +			if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
> +				bcom_gen_bd_rx_reset(s->bcom_task);
> +			else
> +				bcom_gen_bd_tx_reset(s->bcom_task);
>
> -		for (i = 0; i < runtime->periods; i++)
> -			if (!bcom_queue_full(s->bcom_task))
> -				psc_dma_bcom_enqueue_next_buffer(s);
> +			for (i = 0; i < runtime->periods; i++)
> +				if (!bcom_queue_full(s->bcom_task))
> +					psc_dma_bcom_enqueue_next_buffer(s);
>
> -		bcom_enable(s->bcom_task);
> -		spin_unlock_irqrestore(&psc_dma->lock, flags);
> +			bcom_enable(s->bcom_task);
> +		}
>
>  		out_8(&regs->command, MPC52xx_PSC_RST_ERR_STAT);
>
> @@ -158,13 +158,13 @@ static int psc_dma_trigger(struct snd_soc_component *component,
>  			substream->pstr->stream, s->period_count);
>  		s->active = 0;
>
> -		spin_lock_irqsave(&psc_dma->lock, flags);
> -		bcom_disable(s->bcom_task);
> -		if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
> -			bcom_gen_bd_rx_reset(s->bcom_task);
> -		else
> -			bcom_gen_bd_tx_reset(s->bcom_task);
> -		spin_unlock_irqrestore(&psc_dma->lock, flags);
> +		scoped_guard(spinlock_irqsave, &psc_dma->lock) {
> +			bcom_disable(s->bcom_task);
> +			if (substream->pstr->stream == SNDRV_PCM_STREAM_CAPTURE)
> +				bcom_gen_bd_rx_reset(s->bcom_task);
> +			else
> +				bcom_gen_bd_tx_reset(s->bcom_task);
> +		}
>
>  		break;
>
> --
> 2.43.0
>
>

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

* Re: [PATCH v2 04/11] ASoC: fsl_esai: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 04/11] ASoC: fsl_esai: " phucduc.bui
  2026-06-15  9:52   ` sashiko-bot
@ 2026-06-15 14:15   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: Frank Li @ 2026-06-15 14:15 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Shengjiu Wang, Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen,
	Sascha Hauer, Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev

On Mon, Jun 15, 2026 at 04:38:17PM +0700, 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  sound/soc/fsl/fsl_esai.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c
> index cde0b0c6c1ef..4a530a6c33f0 100644
> --- a/sound/soc/fsl/fsl_esai.c
> +++ b/sound/soc/fsl/fsl_esai.c
> @@ -709,10 +709,9 @@ static void fsl_esai_hw_reset(struct work_struct *work)
>  {
>  	struct fsl_esai *esai_priv = container_of(work, struct fsl_esai, work);
>  	bool tx = true, rx = false, enabled[2];
> -	unsigned long lock_flags;
>  	u32 tfcr, rfcr;
>
> -	spin_lock_irqsave(&esai_priv->lock, lock_flags);
> +	guard(spinlock_irqsave)(&esai_priv->lock);
>  	/* Save the registers */
>  	regmap_read(esai_priv->regmap, REG_ESAI_TFCR, &tfcr);
>  	regmap_read(esai_priv->regmap, REG_ESAI_RFCR, &rfcr);
> @@ -750,8 +749,6 @@ static void fsl_esai_hw_reset(struct work_struct *work)
>  		fsl_esai_trigger_start(esai_priv, tx);
>  	if (enabled[rx])
>  		fsl_esai_trigger_start(esai_priv, rx);
> -
> -	spin_unlock_irqrestore(&esai_priv->lock, lock_flags);
>  }
>
>  static int fsl_esai_trigger(struct snd_pcm_substream *substream, int cmd,
> @@ -759,7 +756,6 @@ static int fsl_esai_trigger(struct snd_pcm_substream *substream, int cmd,
>  {
>  	struct fsl_esai *esai_priv = snd_soc_dai_get_drvdata(dai);
>  	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
> -	unsigned long lock_flags;
>
>  	esai_priv->channels[tx] = substream->runtime->channels;
>
> @@ -767,16 +763,14 @@ static int fsl_esai_trigger(struct snd_pcm_substream *substream, int cmd,
>  	case SNDRV_PCM_TRIGGER_START:
>  	case SNDRV_PCM_TRIGGER_RESUME:
>  	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
> -		spin_lock_irqsave(&esai_priv->lock, lock_flags);
> -		fsl_esai_trigger_start(esai_priv, tx);
> -		spin_unlock_irqrestore(&esai_priv->lock, lock_flags);
> +		scoped_guard(spinlock_irqsave, &esai_priv->lock)
> +			fsl_esai_trigger_start(esai_priv, tx);
>  		break;
>  	case SNDRV_PCM_TRIGGER_SUSPEND:
>  	case SNDRV_PCM_TRIGGER_STOP:
>  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
> -		spin_lock_irqsave(&esai_priv->lock, lock_flags);
> -		fsl_esai_trigger_stop(esai_priv, tx);
> -		spin_unlock_irqrestore(&esai_priv->lock, lock_flags);
> +		scoped_guard(spinlock_irqsave, &esai_priv->lock)
> +			fsl_esai_trigger_stop(esai_priv, tx);
>  		break;
>  	default:
>  		return -EINVAL;
> --
> 2.43.0
>
>

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

* Re: [PATCH v2 05/11] ASoC: fsl_spdif: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 05/11] ASoC: fsl_spdif: " phucduc.bui
  2026-06-15  9:52   ` sashiko-bot
@ 2026-06-15 14:17   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: Frank Li @ 2026-06-15 14:17 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Shengjiu Wang, Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen,
	Sascha Hauer, Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev

On Mon, Jun 15, 2026 at 04:38:18PM +0700, 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  sound/soc/fsl/fsl_spdif.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/sound/soc/fsl/fsl_spdif.c b/sound/soc/fsl/fsl_spdif.c
> index 1b9be85b34c2..ad1206ed9882 100644
> --- a/sound/soc/fsl/fsl_spdif.c
> +++ b/sound/soc/fsl/fsl_spdif.c
> @@ -853,17 +853,15 @@ static int fsl_spdif_subcode_get(struct snd_kcontrol *kcontrol,
>  	struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
>  	struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
>  	struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
> -	unsigned long flags;
>  	int ret = -EAGAIN;
>
> -	spin_lock_irqsave(&ctrl->ctl_lock, flags);
> +	guard(spinlock_irqsave)(&ctrl->ctl_lock);
>  	if (ctrl->ready_buf) {
>  		int idx = (ctrl->ready_buf - 1) * SPDIF_UBITS_SIZE;
>  		memcpy(&ucontrol->value.iec958.subcode[0],
>  				&ctrl->subcode[idx], SPDIF_UBITS_SIZE);
>  		ret = 0;
>  	}
> -	spin_unlock_irqrestore(&ctrl->ctl_lock, flags);
>
>  	return ret;
>  }
> @@ -885,17 +883,15 @@ static int fsl_spdif_qget(struct snd_kcontrol *kcontrol,
>  	struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
>  	struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
>  	struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
> -	unsigned long flags;
>  	int ret = -EAGAIN;
>
> -	spin_lock_irqsave(&ctrl->ctl_lock, flags);
> +	guard(spinlock_irqsave)(&ctrl->ctl_lock);
>  	if (ctrl->ready_buf) {
>  		int idx = (ctrl->ready_buf - 1) * SPDIF_QSUB_SIZE;
>  		memcpy(&ucontrol->value.bytes.data[0],
>  				&ctrl->qsub[idx], SPDIF_QSUB_SIZE);
>  		ret = 0;
>  	}
> -	spin_unlock_irqrestore(&ctrl->ctl_lock, flags);
>
>  	return ret;
>  }
> --
> 2.43.0
>
>

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

* Re: [PATCH v2 08/11] ASoC: imx-audio-rpmsg: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 08/11] ASoC: imx-audio-rpmsg: " phucduc.bui
  2026-06-15  9:51   ` sashiko-bot
@ 2026-06-15 14:17   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: Frank Li @ 2026-06-15 14:17 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Shengjiu Wang, Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen,
	Sascha Hauer, Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev

On Mon, Jun 15, 2026 at 04:38:21PM +0700, 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  sound/soc/fsl/imx-audio-rpmsg.c | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/sound/soc/fsl/imx-audio-rpmsg.c b/sound/soc/fsl/imx-audio-rpmsg.c
> index 38aafb8954c7..b55dfbdb4502 100644
> --- a/sound/soc/fsl/imx-audio-rpmsg.c
> +++ b/sound/soc/fsl/imx-audio-rpmsg.c
> @@ -22,7 +22,6 @@ static int imx_audio_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
>  	struct rpmsg_r_msg *r_msg = (struct rpmsg_r_msg *)data;
>  	struct rpmsg_info *info;
>  	struct rpmsg_msg *msg;
> -	unsigned long flags;
>
>  	if (!rpmsg->rpmsg_pdev)
>  		return 0;
> @@ -37,21 +36,21 @@ static int imx_audio_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
>  		/* TYPE C is notification from M core */
>  		switch (r_msg->header.cmd) {
>  		case TX_PERIOD_DONE:
> -			spin_lock_irqsave(&info->lock[TX], flags);
> -			msg = &info->msg[TX_PERIOD_DONE + MSG_TYPE_A_NUM];
> -			msg->r_msg.param.buffer_tail =
> -						r_msg->param.buffer_tail;
> -			msg->r_msg.param.buffer_tail %= info->num_period[TX];
> -			spin_unlock_irqrestore(&info->lock[TX], flags);
> +			scoped_guard(spinlock_irqsave, &info->lock[TX]) {
> +				msg = &info->msg[TX_PERIOD_DONE + MSG_TYPE_A_NUM];
> +				msg->r_msg.param.buffer_tail =
> +							r_msg->param.buffer_tail;
> +				msg->r_msg.param.buffer_tail %= info->num_period[TX];
> +			}
>  			info->callback[TX](info->callback_param[TX]);
>  			break;
>  		case RX_PERIOD_DONE:
> -			spin_lock_irqsave(&info->lock[RX], flags);
> -			msg = &info->msg[RX_PERIOD_DONE + MSG_TYPE_A_NUM];
> -			msg->r_msg.param.buffer_tail =
> -						r_msg->param.buffer_tail;
> -			msg->r_msg.param.buffer_tail %= info->num_period[1];
> -			spin_unlock_irqrestore(&info->lock[RX], flags);
> +			scoped_guard(spinlock_irqsave, &info->lock[RX]) {
> +				msg = &info->msg[RX_PERIOD_DONE + MSG_TYPE_A_NUM];
> +				msg->r_msg.param.buffer_tail =
> +							r_msg->param.buffer_tail;
> +				msg->r_msg.param.buffer_tail %= info->num_period[1];
> +			}
>  			info->callback[RX](info->callback_param[RX]);
>  			break;
>  		default:
> --
> 2.43.0
>
>

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

* Re: [PATCH v2 01/11] ASoC: fsl_asrc: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 01/11] ASoC: fsl_asrc: Use guard() for " phucduc.bui
  2026-06-15  9:51   ` sashiko-bot
@ 2026-06-15 14:18   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: Frank Li @ 2026-06-15 14:18 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Shengjiu Wang, Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen,
	Sascha Hauer, Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev

On Mon, Jun 15, 2026 at 04:38:14PM +0700, 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  sound/soc/fsl/fsl_asrc.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
> index 5fda9b647c70..0b28bcfa47fe 100644
> --- a/sound/soc/fsl/fsl_asrc.c
> +++ b/sound/soc/fsl/fsl_asrc.c
> @@ -222,10 +222,9 @@ static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair)
>  	enum asrc_pair_index index = ASRC_INVALID_PAIR;
>  	struct fsl_asrc *asrc = pair->asrc;
>  	struct device *dev = &asrc->pdev->dev;
> -	unsigned long lock_flags;
>  	int i, ret = 0;
>
> -	spin_lock_irqsave(&asrc->lock, lock_flags);
> +	guard(spinlock_irqsave)(&asrc->lock);
>
>  	for (i = ASRC_PAIR_A; i < ASRC_PAIR_MAX_NUM; i++) {
>  		if (asrc->pair[i] != NULL)
> @@ -250,8 +249,6 @@ static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair)
>  		pair->index = index;
>  	}
>
> -	spin_unlock_irqrestore(&asrc->lock, lock_flags);
> -
>  	return ret;
>  }
>
> @@ -265,19 +262,16 @@ static void fsl_asrc_release_pair(struct fsl_asrc_pair *pair)
>  {
>  	struct fsl_asrc *asrc = pair->asrc;
>  	enum asrc_pair_index index = pair->index;
> -	unsigned long lock_flags;
>
>  	/* Make sure the pair is disabled */
>  	regmap_update_bits(asrc->regmap, REG_ASRCTR,
>  			   ASRCTR_ASRCEi_MASK(index), 0);
>
> -	spin_lock_irqsave(&asrc->lock, lock_flags);
> +	guard(spinlock_irqsave)(&asrc->lock);
>
>  	asrc->channel_avail += pair->channels;
>  	asrc->pair[index] = NULL;
>  	pair->error = 0;
> -
> -	spin_unlock_irqrestore(&asrc->lock, lock_flags);
>  }
>
>  /**
> --
> 2.43.0
>
>


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

* Re: [PATCH v2 07/11] ASoC: fsl_xcvr: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 07/11] ASoC: fsl_xcvr: Use guard() for spin locks phucduc.bui
  2026-06-15  9:49   ` sashiko-bot
@ 2026-06-15 14:19   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: Frank Li @ 2026-06-15 14:19 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Shengjiu Wang, Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen,
	Sascha Hauer, Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev

On Mon, Jun 15, 2026 at 04:38:20PM +0700, 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  sound/soc/fsl/fsl_xcvr.c | 29 ++++++++++++-----------------
>  1 file changed, 12 insertions(+), 17 deletions(-)
>
> diff --git a/sound/soc/fsl/fsl_xcvr.c b/sound/soc/fsl/fsl_xcvr.c
> index 6677d3bf36ec..41d100500534 100644
> --- a/sound/soc/fsl/fsl_xcvr.c
> +++ b/sound/soc/fsl/fsl_xcvr.c
> @@ -797,10 +797,9 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
>  {
>  	struct fsl_xcvr *xcvr = snd_soc_dai_get_drvdata(dai);
>  	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
> -	unsigned long lock_flags;
>  	int ret = 0;
>
> -	spin_lock_irqsave(&xcvr->lock, lock_flags);
> +	guard(spinlock_irqsave)(&xcvr->lock);
>
>  	switch (cmd) {
>  	case SNDRV_PCM_TRIGGER_START:
> @@ -812,7 +811,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
>  					 FSL_XCVR_EXT_CTRL_DPTH_RESET(tx));
>  		if (ret < 0) {
>  			dev_err(dai->dev, "Failed to set DPATH RESET: %d\n", ret);
> -			goto release_lock;
> +			return ret;
>  		}
>
>  		if (tx) {
> @@ -824,7 +823,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
>  						   FSL_XCVR_ISR_CMDC_TX_EN);
>  				if (ret < 0) {
>  					dev_err(dai->dev, "err updating isr %d\n", ret);
> -					goto release_lock;
> +					return ret;
>  				}
>  				fallthrough;
>  			case FSL_XCVR_MODE_SPDIF:
> @@ -833,7 +832,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
>  						      FSL_XCVR_TX_DPTH_CTRL_STRT_DATA_TX);
>  				if (ret < 0) {
>  					dev_err(dai->dev, "Failed to start DATA_TX: %d\n", ret);
> -					goto release_lock;
> +					return ret;
>  				}
>  				break;
>  			}
> @@ -844,14 +843,14 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
>  					 FSL_XCVR_EXT_CTRL_DMA_DIS(tx), 0);
>  		if (ret < 0) {
>  			dev_err(dai->dev, "Failed to enable DMA: %d\n", ret);
> -			goto release_lock;
> +			return ret;
>  		}
>
>  		ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_IER0,
>  					 FSL_XCVR_IRQ_EARC_ALL, FSL_XCVR_IRQ_EARC_ALL);
>  		if (ret < 0) {
>  			dev_err(dai->dev, "Error while setting IER0: %d\n", ret);
> -			goto release_lock;
> +			return ret;
>  		}
>
>  		/* clear DPATH RESET */
> @@ -860,7 +859,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
>  					 0);
>  		if (ret < 0) {
>  			dev_err(dai->dev, "Failed to clear DPATH RESET: %d\n", ret);
> -			goto release_lock;
> +			return ret;
>  		}
>
>  		break;
> @@ -873,14 +872,14 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
>  					 FSL_XCVR_EXT_CTRL_DMA_DIS(tx));
>  		if (ret < 0) {
>  			dev_err(dai->dev, "Failed to disable DMA: %d\n", ret);
> -			goto release_lock;
> +			return ret;
>  		}
>
>  		ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_IER0,
>  					 FSL_XCVR_IRQ_EARC_ALL, 0);
>  		if (ret < 0) {
>  			dev_err(dai->dev, "Failed to clear IER0: %d\n", ret);
> -			goto release_lock;
> +			return ret;
>  		}
>
>  		if (tx) {
> @@ -891,7 +890,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
>  							FSL_XCVR_TX_DPTH_CTRL_STRT_DATA_TX);
>  				if (ret < 0) {
>  					dev_err(dai->dev, "Failed to stop DATA_TX: %d\n", ret);
> -					goto release_lock;
> +					return ret;
>  				}
>  				if (xcvr->soc_data->spdif_only)
>  					break;
> @@ -905,7 +904,7 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
>  				if (ret < 0) {
>  					dev_err(dai->dev,
>  						"Err updating ISR %d\n", ret);
> -					goto release_lock;
> +					return ret;
>  				}
>  				break;
>  			}
> @@ -916,8 +915,6 @@ static int fsl_xcvr_trigger(struct snd_pcm_substream *substream, int cmd,
>  		break;
>  	}
>
> -release_lock:
> -	spin_unlock_irqrestore(&xcvr->lock, lock_flags);
>  	return ret;
>  }
>
> @@ -1448,11 +1445,10 @@ static void reset_rx_work(struct work_struct *work)
>  {
>  	struct fsl_xcvr *xcvr = container_of(work, struct fsl_xcvr, work_rst);
>  	struct device *dev = &xcvr->pdev->dev;
> -	unsigned long lock_flags;
>  	u32 ext_ctrl;
>
>  	dev_dbg(dev, "reset rx path\n");
> -	spin_lock_irqsave(&xcvr->lock, lock_flags);
> +	guard(spinlock_irqsave)(&xcvr->lock);
>  	regmap_read(xcvr->regmap, FSL_XCVR_EXT_CTRL, &ext_ctrl);
>
>  	if (!(ext_ctrl & FSL_XCVR_EXT_CTRL_DMA_RD_DIS)) {
> @@ -1469,7 +1465,6 @@ static void reset_rx_work(struct work_struct *work)
>  				   FSL_XCVR_EXT_CTRL_RX_DPTH_RESET,
>  				   0);
>  	}
> -	spin_unlock_irqrestore(&xcvr->lock, lock_flags);
>  }
>
>  static irqreturn_t irq0_isr(int irq, void *devid)
> --
> 2.43.0
>
>

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

* Re: [PATCH v2 03/11] ASoC: fsl_easrc: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 03/11] ASoC: fsl_easrc: " phucduc.bui
  2026-06-15  9:48   ` sashiko-bot
@ 2026-06-15 14:24   ` Frank Li
  1 sibling, 0 replies; 31+ messages in thread
From: Frank Li @ 2026-06-15 14:24 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Shengjiu Wang, Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen,
	Sascha Hauer, Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev

On Mon, Jun 15, 2026 at 04:38:16PM +0700, 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  sound/soc/fsl/fsl_easrc.c | 36 ++++++++++--------------------------
>  1 file changed, 10 insertions(+), 26 deletions(-)
>
> diff --git a/sound/soc/fsl/fsl_easrc.c b/sound/soc/fsl/fsl_easrc.c
> index 114a6c0b6b73..edfd943197a0 100644
> --- a/sound/soc/fsl/fsl_easrc.c
> +++ b/sound/soc/fsl/fsl_easrc.c
> @@ -1025,7 +1025,6 @@ static int fsl_easrc_config_context(struct fsl_asrc *easrc, unsigned int ctx_id)
>  	struct fsl_easrc_ctx_priv *ctx_priv;
>  	struct fsl_asrc_pair *ctx;
>  	struct device *dev;
> -	unsigned long lock_flags;
>  	int ret;
>
>  	if (!easrc)
> @@ -1053,9 +1052,8 @@ static int fsl_easrc_config_context(struct fsl_asrc *easrc, unsigned int ctx_id)
>  	if (ret)
>  		return ret;
>
> -	spin_lock_irqsave(&easrc->lock, lock_flags);
> -	ret = fsl_easrc_config_slot(easrc, ctx->index);
> -	spin_unlock_irqrestore(&easrc->lock, lock_flags);
> +	scoped_guard(spinlock_irqsave, &easrc->lock)
> +		ret = fsl_easrc_config_slot(easrc, ctx->index);
>  	if (ret)
>  		return ret;
>
> @@ -1301,13 +1299,12 @@ static int fsl_easrc_request_context(int channels, struct fsl_asrc_pair *ctx)
>  	enum asrc_pair_index index = ASRC_INVALID_PAIR;
>  	struct fsl_asrc *easrc = ctx->asrc;
>  	struct device *dev;
> -	unsigned long lock_flags;
>  	int ret = 0;
>  	int i;
>
>  	dev = &easrc->pdev->dev;
>
> -	spin_lock_irqsave(&easrc->lock, lock_flags);
> +	guard(spinlock_irqsave)(&easrc->lock);
>
>  	for (i = ASRC_PAIR_A; i < EASRC_CTX_MAX_NUM; i++) {
>  		if (easrc->pair[i])
> @@ -1331,8 +1328,6 @@ static int fsl_easrc_request_context(int channels, struct fsl_asrc_pair *ctx)
>  		easrc->channel_avail -= channels;
>  	}
>
> -	spin_unlock_irqrestore(&easrc->lock, lock_flags);
> -
>  	return ret;
>  }
>
> @@ -1343,7 +1338,6 @@ static int fsl_easrc_request_context(int channels, struct fsl_asrc_pair *ctx)
>   */
>  static void fsl_easrc_release_context(struct fsl_asrc_pair *ctx)
>  {
> -	unsigned long lock_flags;
>  	struct fsl_asrc *easrc;
>
>  	if (!ctx)
> @@ -1351,14 +1345,12 @@ static void fsl_easrc_release_context(struct fsl_asrc_pair *ctx)
>
>  	easrc = ctx->asrc;
>
> -	spin_lock_irqsave(&easrc->lock, lock_flags);
> +	guard(spinlock_irqsave)(&easrc->lock);
>
>  	fsl_easrc_release_slot(easrc, ctx->index);
>
>  	easrc->channel_avail += ctx->channels;
>  	easrc->pair[ctx->index] = NULL;
> -
> -	spin_unlock_irqrestore(&easrc->lock, lock_flags);
>  }
>
>  /*
> @@ -2292,15 +2284,13 @@ static int fsl_easrc_runtime_suspend(struct device *dev)
>  {
>  	struct fsl_asrc *easrc = dev_get_drvdata(dev);
>  	struct fsl_easrc_priv *easrc_priv = easrc->private;
> -	unsigned long lock_flags;
>
>  	regcache_cache_only(easrc->regmap, true);
>
>  	clk_disable_unprepare(easrc->mem_clk);
>
> -	spin_lock_irqsave(&easrc->lock, lock_flags);
> -	easrc_priv->firmware_loaded = 0;
> -	spin_unlock_irqrestore(&easrc->lock, lock_flags);
> +	scoped_guard(spinlock_irqsave, &easrc->lock)
> +		easrc_priv->firmware_loaded = 0;
>
>  	return 0;
>  }
> @@ -2311,7 +2301,6 @@ static int fsl_easrc_runtime_resume(struct device *dev)
>  	struct fsl_easrc_priv *easrc_priv = easrc->private;
>  	struct fsl_easrc_ctx_priv *ctx_priv;
>  	struct fsl_asrc_pair *ctx;
> -	unsigned long lock_flags;
>  	int ret;
>  	int i;
>
> @@ -2323,13 +2312,11 @@ static int fsl_easrc_runtime_resume(struct device *dev)
>  	regcache_mark_dirty(easrc->regmap);
>  	regcache_sync(easrc->regmap);
>
> -	spin_lock_irqsave(&easrc->lock, lock_flags);
> -	if (easrc_priv->firmware_loaded) {
> -		spin_unlock_irqrestore(&easrc->lock, lock_flags);
> -		goto skip_load;
> +	scoped_guard(spinlock_irqsave, &easrc->lock) {
> +		if (easrc_priv->firmware_loaded)
> +			return 0;
> +		easrc_priv->firmware_loaded = 1;
>  	}
> -	easrc_priv->firmware_loaded = 1;
> -	spin_unlock_irqrestore(&easrc->lock, lock_flags);
>
>  	ret = fsl_easrc_get_firmware(easrc);
>  	if (ret) {
> @@ -2377,9 +2364,6 @@ static int fsl_easrc_runtime_resume(struct device *dev)
>  			goto disable_mem_clk;
>  	}
>
> -skip_load:
> -	return 0;
> -
>  disable_mem_clk:
>  	clk_disable_unprepare(easrc->mem_clk);
>  	return ret;
> --
> 2.43.0
>
>

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

* Re: [PATCH v2 06/11] ASoC: fsl_ssi: Use guard() for mutex locks
  2026-06-15  9:38 ` [PATCH v2 06/11] ASoC: fsl_ssi: Use guard() for mutex locks phucduc.bui
@ 2026-06-15 14:25   ` Frank Li
  0 siblings, 0 replies; 31+ messages in thread
From: Frank Li @ 2026-06-15 14:25 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Shengjiu Wang, Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen,
	Sascha Hauer, Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev

On Mon, Jun 15, 2026 at 04:38:19PM +0700, phucduc.bui@gmail.com wrote:
> 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  sound/soc/fsl/fsl_ssi.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
> index b2e1da1781ae..dc022976c982 100644
> --- a/sound/soc/fsl/fsl_ssi.c
> +++ b/sound/soc/fsl/fsl_ssi.c
> @@ -1218,13 +1218,13 @@ static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
>  	if (reg > 0x7f)
>  		return;
>
> -	mutex_lock(&fsl_ac97_data->ac97_reg_lock);
> +	guard(mutex)(&fsl_ac97_data->ac97_reg_lock);
>
>  	ret = clk_prepare_enable(fsl_ac97_data->clk);
>  	if (ret) {
>  		pr_err("ac97 write clk_prepare_enable failed: %d\n",
>  			ret);
> -		goto ret_unlock;
> +		return;
>  	}
>
>  	lreg = reg <<  12;
> @@ -1238,9 +1238,6 @@ static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
>  	udelay(100);
>
>  	clk_disable_unprepare(fsl_ac97_data->clk);
> -
> -ret_unlock:
> -	mutex_unlock(&fsl_ac97_data->ac97_reg_lock);
>  }
>
>  static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
> @@ -1252,12 +1249,12 @@ static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
>  	unsigned int lreg;
>  	int ret;
>
> -	mutex_lock(&fsl_ac97_data->ac97_reg_lock);
> +	guard(mutex)(&fsl_ac97_data->ac97_reg_lock);
>
>  	ret = clk_prepare_enable(fsl_ac97_data->clk);
>  	if (ret) {
>  		pr_err("ac97 read clk_prepare_enable failed: %d\n", ret);
> -		goto ret_unlock;
> +		return val;
>  	}
>
>  	lreg = (reg & 0x7f) <<  12;
> @@ -1272,8 +1269,6 @@ static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
>
>  	clk_disable_unprepare(fsl_ac97_data->clk);
>
> -ret_unlock:
> -	mutex_unlock(&fsl_ac97_data->ac97_reg_lock);
>  	return val;
>  }
>
> --
> 2.43.0
>
>

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

* Re: [PATCH v2 11/11] ASoC: fsl: mpc5200_psc_ac97: Use guard() for mutex locks
  2026-06-15  9:38 ` [PATCH v2 11/11] ASoC: fsl: mpc5200_psc_ac97: Use guard() for mutex locks phucduc.bui
@ 2026-06-15 14:26   ` Frank Li
  0 siblings, 0 replies; 31+ messages in thread
From: Frank Li @ 2026-06-15 14:26 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Shengjiu Wang, Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen,
	Sascha Hauer, Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev

On Mon, Jun 15, 2026 at 04:38:24PM +0700, phucduc.bui@gmail.com wrote:
> 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>
> Changes in v2:
>  - psc_ac97_cold_reset(): Fix scoped_guard() usage by replacing
>    scoped_guard(mutex_lock, ...) with scoped_guard(mutex, ...).
>
>  sound/soc/fsl/mpc5200_psc_ac97.c | 34 +++++++++++---------------------
>  1 file changed, 12 insertions(+), 22 deletions(-)
>
> diff --git a/sound/soc/fsl/mpc5200_psc_ac97.c b/sound/soc/fsl/mpc5200_psc_ac97.c
> index 8554fb690772..d4d9f5b6bc07 100644
> --- a/sound/soc/fsl/mpc5200_psc_ac97.c
> +++ b/sound/soc/fsl/mpc5200_psc_ac97.c
> @@ -31,14 +31,13 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
>  	int status;
>  	unsigned int val;
>
> -	mutex_lock(&psc_dma->mutex);
> +	guard(mutex)(&psc_dma->mutex);
>
>  	/* Wait for command send status zero = ready */
>  	status = spin_event_timeout(!(in_be16(&psc_dma->psc_regs->sr_csr.status) &
>  				MPC52xx_PSC_SR_CMDSEND), 100, 0);
>  	if (status == 0) {
>  		pr_err("timeout on ac97 bus (rdy)\n");
> -		mutex_unlock(&psc_dma->mutex);
>  		return -ENODEV;
>  	}
>
> @@ -54,19 +53,16 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
>  	if (status == 0) {
>  		pr_err("timeout on ac97 read (val) %x\n",
>  				in_be16(&psc_dma->psc_regs->sr_csr.status));
> -		mutex_unlock(&psc_dma->mutex);
>  		return -ENODEV;
>  	}
>  	/* Get the data */
>  	val = in_be32(&psc_dma->psc_regs->ac97_data);
>  	if (((val >> 24) & 0x7f) != reg) {
>  		pr_err("reg echo error on ac97 read\n");
> -		mutex_unlock(&psc_dma->mutex);
>  		return -ENODEV;
>  	}
>  	val = (val >> 8) & 0xffff;
>
> -	mutex_unlock(&psc_dma->mutex);
>  	return (unsigned short) val;
>  }
>
> @@ -75,52 +71,46 @@ static void psc_ac97_write(struct snd_ac97 *ac97,
>  {
>  	int status;
>
> -	mutex_lock(&psc_dma->mutex);
> +	guard(mutex)(&psc_dma->mutex);
>
>  	/* Wait for command status zero = ready */
>  	status = spin_event_timeout(!(in_be16(&psc_dma->psc_regs->sr_csr.status) &
>  				MPC52xx_PSC_SR_CMDSEND), 100, 0);
>  	if (status == 0) {
>  		pr_err("timeout on ac97 bus (write)\n");
> -		goto out;
> +		return;
>  	}
>  	/* Write data */
>  	out_be32(&psc_dma->psc_regs->ac97_cmd,
>  			((reg & 0x7f) << 24) | (val << 8));
> -
> - out:
> -	mutex_unlock(&psc_dma->mutex);
>  }
>
>  static void psc_ac97_warm_reset(struct snd_ac97 *ac97)
>  {
>  	struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
>
> -	mutex_lock(&psc_dma->mutex);
> +	guard(mutex)(&psc_dma->mutex);
>
>  	out_be32(&regs->sicr, psc_dma->sicr | MPC52xx_PSC_SICR_AWR);
>  	udelay(3);
>  	out_be32(&regs->sicr, psc_dma->sicr);
> -
> -	mutex_unlock(&psc_dma->mutex);
>  }
>
>  static void psc_ac97_cold_reset(struct snd_ac97 *ac97)
>  {
>  	struct mpc52xx_psc __iomem *regs = psc_dma->psc_regs;
>
> -	mutex_lock(&psc_dma->mutex);
> -	dev_dbg(psc_dma->dev, "cold reset\n");
> +	scoped_guard(mutex, &psc_dma->mutex) {
> +		dev_dbg(psc_dma->dev, "cold reset\n");
>
> -	mpc5200_psc_ac97_gpio_reset(psc_dma->id);
> +		mpc5200_psc_ac97_gpio_reset(psc_dma->id);
>
> -	/* Notify the PSC that a reset has occurred */
> -	out_be32(&regs->sicr, psc_dma->sicr | MPC52xx_PSC_SICR_ACRB);
> +		/* Notify the PSC that a reset has occurred */
> +		out_be32(&regs->sicr, psc_dma->sicr | MPC52xx_PSC_SICR_ACRB);
>
> -	/* Re-enable RX and TX */
> -	out_8(&regs->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE);
> -
> -	mutex_unlock(&psc_dma->mutex);
> +		/* Re-enable RX and TX */
> +		out_8(&regs->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE);
> +	}
>
>  	usleep_range(1000, 2000);
>  	psc_ac97_warm_reset(ac97);
> --
> 2.43.0
>
>

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

* Re: [PATCH v2 02/11] ASoC: fsl_audmix: Use guard() for spin locks
  2026-06-15  9:38 ` [PATCH v2 02/11] ASoC: fsl_audmix: " phucduc.bui
@ 2026-06-15 14:30   ` Frank Li
  0 siblings, 0 replies; 31+ messages in thread
From: Frank Li @ 2026-06-15 14:30 UTC (permalink / raw)
  To: phucduc.bui
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Shengjiu Wang, Xiubo Li, Frank Li, Fabio Estevam, Nicolin Chen,
	Sascha Hauer, Pengutronix Kernel Team, linux-sound, linux-kernel,
	linux-arm-kernel, imx, linuxppc-dev

On Mon, Jun 15, 2026 at 04:38:15PM +0700, 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  sound/soc/fsl/fsl_audmix.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/sound/soc/fsl/fsl_audmix.c b/sound/soc/fsl/fsl_audmix.c
> index 40a3b7432174..066239c64037 100644
> --- a/sound/soc/fsl/fsl_audmix.c
> +++ b/sound/soc/fsl/fsl_audmix.c
> @@ -280,7 +280,6 @@ static int fsl_audmix_dai_trigger(struct snd_pcm_substream *substream, int cmd,
>  				  struct snd_soc_dai *dai)
>  {
>  	struct fsl_audmix *priv = snd_soc_dai_get_drvdata(dai);
> -	unsigned long lock_flags;
>
>  	/* Capture stream shall not be handled */
>  	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
> @@ -290,16 +289,14 @@ static int fsl_audmix_dai_trigger(struct snd_pcm_substream *substream, int cmd,
>  	case SNDRV_PCM_TRIGGER_START:
>  	case SNDRV_PCM_TRIGGER_RESUME:
>  	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
> -		spin_lock_irqsave(&priv->lock, lock_flags);
> -		priv->tdms |= BIT(dai->driver->id);
> -		spin_unlock_irqrestore(&priv->lock, lock_flags);
> +		scoped_guard(spinlock_irqsave, &priv->lock)
> +			priv->tdms |= BIT(dai->driver->id);
>  		break;
>  	case SNDRV_PCM_TRIGGER_STOP:
>  	case SNDRV_PCM_TRIGGER_SUSPEND:
>  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
> -		spin_lock_irqsave(&priv->lock, lock_flags);
> -		priv->tdms &= ~BIT(dai->driver->id);
> -		spin_unlock_irqrestore(&priv->lock, lock_flags);
> +		scoped_guard(spinlock_irqsave, &priv->lock)
> +			priv->tdms &= ~BIT(dai->driver->id);
>  		break;
>  	default:
>  		return -EINVAL;
> --
> 2.43.0
>
>


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

end of thread, other threads:[~2026-06-15 14:31 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-15  9:38 [PATCH v2 00/11] ASoC: fsl: Use guard() for mutex & spin locks phucduc.bui
2026-06-15  9:38 ` [PATCH v2 01/11] ASoC: fsl_asrc: Use guard() for " phucduc.bui
2026-06-15  9:51   ` sashiko-bot
2026-06-15 14:18   ` Frank Li
2026-06-15  9:38 ` [PATCH v2 02/11] ASoC: fsl_audmix: " phucduc.bui
2026-06-15 14:30   ` Frank Li
2026-06-15  9:38 ` [PATCH v2 03/11] ASoC: fsl_easrc: " phucduc.bui
2026-06-15  9:48   ` sashiko-bot
2026-06-15 14:24   ` Frank Li
2026-06-15  9:38 ` [PATCH v2 04/11] ASoC: fsl_esai: " phucduc.bui
2026-06-15  9:52   ` sashiko-bot
2026-06-15 14:15   ` Frank Li
2026-06-15  9:38 ` [PATCH v2 05/11] ASoC: fsl_spdif: " phucduc.bui
2026-06-15  9:52   ` sashiko-bot
2026-06-15 14:17   ` Frank Li
2026-06-15  9:38 ` [PATCH v2 06/11] ASoC: fsl_ssi: Use guard() for mutex locks phucduc.bui
2026-06-15 14:25   ` Frank Li
2026-06-15  9:38 ` [PATCH v2 07/11] ASoC: fsl_xcvr: Use guard() for spin locks phucduc.bui
2026-06-15  9:49   ` sashiko-bot
2026-06-15 14:19   ` Frank Li
2026-06-15  9:38 ` [PATCH v2 08/11] ASoC: imx-audio-rpmsg: " phucduc.bui
2026-06-15  9:51   ` sashiko-bot
2026-06-15 14:17   ` Frank Li
2026-06-15  9:38 ` [PATCH v2 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & " phucduc.bui
2026-06-15  9:59   ` sashiko-bot
2026-06-15 14:12   ` Frank Li
2026-06-15  9:38 ` [PATCH v2 10/11] ASoC: fsl: mpc5200_dma: Use guard() for " phucduc.bui
2026-06-15  9:57   ` sashiko-bot
2026-06-15 14:14   ` Frank Li
2026-06-15  9:38 ` [PATCH v2 11/11] ASoC: fsl: mpc5200_psc_ac97: Use guard() for mutex locks phucduc.bui
2026-06-15 14:26   ` Frank Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.