Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/2] ASoC: sti: Use guard() for mutex & spin locks
@ 2026-05-27 10:02 phucduc.bui
  2026-05-27 10:02 ` [PATCH 1/2] ASoC: sti: uniperif_reader: Use guard() for " phucduc.bui
  2026-05-27 10:02 ` [PATCH 2/2] ASoC: sti: uniperif_player: Use guard() for mutex & " phucduc.bui
  0 siblings, 2 replies; 3+ messages in thread
From: phucduc.bui @ 2026-05-27 10:02 UTC (permalink / raw)
  To: Mark Brown, Arnaud Pouliquen
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, linux-sound,
	linux-kernel, bui duc phuc

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

Hi all,

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

Best regards,
Phuc

bui duc phuc (2):
  ASoC: sti: uniperif_reader: Use guard() for spin locks
  ASoC: sti: uniperif_player: Use guard() for mutex & spin locks

 sound/soc/sti/uniperif_player.c | 73 ++++++++++++++-------------------
 sound/soc/sti/uniperif_reader.c | 20 ++++-----
 2 files changed, 38 insertions(+), 55 deletions(-)

-- 
2.43.0


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

* [PATCH 1/2] ASoC: sti: uniperif_reader: Use guard() for spin locks
  2026-05-27 10:02 [PATCH 0/2] ASoC: sti: Use guard() for mutex & spin locks phucduc.bui
@ 2026-05-27 10:02 ` phucduc.bui
  2026-05-27 10:02 ` [PATCH 2/2] ASoC: sti: uniperif_player: Use guard() for mutex & " phucduc.bui
  1 sibling, 0 replies; 3+ messages in thread
From: phucduc.bui @ 2026-05-27 10:02 UTC (permalink / raw)
  To: Mark Brown, Arnaud Pouliquen
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, linux-sound,
	linux-kernel, bui duc phuc

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

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

Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---

Compile-tested only.

 sound/soc/sti/uniperif_reader.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/sound/soc/sti/uniperif_reader.c b/sound/soc/sti/uniperif_reader.c
index 05ea2b794eb9..45d7613f595c 100644
--- a/sound/soc/sti/uniperif_reader.c
+++ b/sound/soc/sti/uniperif_reader.c
@@ -46,15 +46,16 @@ static irqreturn_t uni_reader_irq_handler(int irq, void *dev_id)
 	struct uniperif *reader = dev_id;
 	unsigned int status;
 
-	spin_lock(&reader->irq_lock);
+	guard(spinlock)(&reader->irq_lock);
 	if (!reader->substream)
-		goto irq_spin_unlock;
+		return ret;
 
 	snd_pcm_stream_lock(reader->substream);
 	if (reader->state == UNIPERIF_STATE_STOPPED) {
 		/* Unexpected IRQ: do nothing */
 		dev_warn(reader->dev, "unexpected IRQ\n");
-		goto stream_unlock;
+		snd_pcm_stream_unlock(reader->substream);
+		return ret;
 	}
 
 	/* Get interrupt status & clear them immediately */
@@ -70,10 +71,7 @@ static irqreturn_t uni_reader_irq_handler(int irq, void *dev_id)
 		ret = IRQ_HANDLED;
 	}
 
-stream_unlock:
 	snd_pcm_stream_unlock(reader->substream);
-irq_spin_unlock:
-	spin_unlock(&reader->irq_lock);
 
 	return ret;
 }
@@ -355,12 +353,10 @@ static int uni_reader_startup(struct snd_pcm_substream *substream,
 {
 	struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
 	struct uniperif *reader = priv->dai_data.uni;
-	unsigned long flags;
 	int ret;
 
-	spin_lock_irqsave(&reader->irq_lock, flags);
-	reader->substream = substream;
-	spin_unlock_irqrestore(&reader->irq_lock, flags);
+	scoped_guard(spinlock_irqsave, &reader->irq_lock)
+		reader->substream = substream;
 
 	if (!UNIPERIF_TYPE_IS_TDM(reader))
 		return 0;
@@ -386,15 +382,13 @@ static void uni_reader_shutdown(struct snd_pcm_substream *substream,
 {
 	struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
 	struct uniperif *reader = priv->dai_data.uni;
-	unsigned long flags;
 
-	spin_lock_irqsave(&reader->irq_lock, flags);
+	guard(spinlock_irqsave)(&reader->irq_lock);
 	if (reader->state != UNIPERIF_STATE_STOPPED) {
 		/* Stop the reader */
 		uni_reader_stop(reader);
 	}
 	reader->substream = NULL;
-	spin_unlock_irqrestore(&reader->irq_lock, flags);
 }
 
 static const struct snd_soc_dai_ops uni_reader_dai_ops = {
-- 
2.43.0


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

* [PATCH 2/2] ASoC: sti: uniperif_player: Use guard() for mutex & spin locks
  2026-05-27 10:02 [PATCH 0/2] ASoC: sti: Use guard() for mutex & spin locks phucduc.bui
  2026-05-27 10:02 ` [PATCH 1/2] ASoC: sti: uniperif_reader: Use guard() for " phucduc.bui
@ 2026-05-27 10:02 ` phucduc.bui
  1 sibling, 0 replies; 3+ messages in thread
From: phucduc.bui @ 2026-05-27 10:02 UTC (permalink / raw)
  To: Mark Brown, Arnaud Pouliquen
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, linux-sound,
	linux-kernel, bui duc phuc

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

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

Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---

Compile-tested only.

 sound/soc/sti/uniperif_player.c | 73 ++++++++++++++-------------------
 1 file changed, 31 insertions(+), 42 deletions(-)

diff --git a/sound/soc/sti/uniperif_player.c b/sound/soc/sti/uniperif_player.c
index 45d35b887e4e..e4b9799ad9b2 100644
--- a/sound/soc/sti/uniperif_player.c
+++ b/sound/soc/sti/uniperif_player.c
@@ -65,13 +65,15 @@ static irqreturn_t uni_player_irq_handler(int irq, void *dev_id)
 	unsigned int status;
 	unsigned int tmp;
 
-	spin_lock(&player->irq_lock);
+	guard(spinlock)(&player->irq_lock);
 	if (!player->substream)
-		goto irq_spin_unlock;
+		return ret;
 
 	snd_pcm_stream_lock(player->substream);
-	if (player->state == UNIPERIF_STATE_STOPPED)
-		goto stream_unlock;
+	if (player->state == UNIPERIF_STATE_STOPPED) {
+		snd_pcm_stream_unlock(player->substream);
+		return ret;
+	}
 
 	/* Get interrupt status & clear them immediately */
 	status = GET_UNIPERIF_ITS(player);
@@ -116,7 +118,8 @@ static irqreturn_t uni_player_irq_handler(int irq, void *dev_id)
 			dev_err(player->dev,
 				"unexpected Underflow recovering\n");
 			ret = -EPERM;
-			goto stream_unlock;
+			snd_pcm_stream_unlock(player->substream);
+			return ret;
 		}
 		/* Read the underflow recovery duration */
 		tmp = GET_UNIPERIF_STATUS_1_UNDERFLOW_DURATION(player);
@@ -143,10 +146,7 @@ static irqreturn_t uni_player_irq_handler(int irq, void *dev_id)
 		ret = IRQ_HANDLED;
 	}
 
-stream_unlock:
 	snd_pcm_stream_unlock(player->substream);
-irq_spin_unlock:
-	spin_unlock(&player->irq_lock);
 
 	return ret;
 }
@@ -363,10 +363,10 @@ static int uni_player_prepare_iec958(struct uniperif *player,
 
 	SET_UNIPERIF_CTRL_ZERO_STUFF_HW(player);
 
-	mutex_lock(&player->ctrl_lock);
 	/* Update the channel status */
-	uni_player_set_channel_status(player, runtime);
-	mutex_unlock(&player->ctrl_lock);
+	scoped_guard(mutex, &player->ctrl_lock)
+		uni_player_set_channel_status(player, runtime);
+
 
 	/* Clear the user validity user bits */
 	SET_UNIPERIF_USER_VALIDITY_VALIDITY_LR(player, 0);
@@ -546,11 +546,11 @@ static int uni_player_prepare_tdm(struct uniperif *player,
 
 	/* set unip clk rate (not done vai set_sysclk ops) */
 	freq = runtime->rate * tdm_frame_size * 8;
-	mutex_lock(&player->ctrl_lock);
-	ret = uni_player_clk_set_rate(player, freq);
-	if (!ret)
-		player->mclk = freq;
-	mutex_unlock(&player->ctrl_lock);
+	scoped_guard(mutex, &player->ctrl_lock) {
+		ret = uni_player_clk_set_rate(player, freq);
+		if (!ret)
+			player->mclk = freq;
+	}
 
 	return 0;
 }
@@ -575,12 +575,11 @@ static int uni_player_ctl_iec958_get(struct snd_kcontrol *kcontrol,
 	struct uniperif *player = priv->dai_data.uni;
 	struct snd_aes_iec958 *iec958 = &player->stream_settings.iec958;
 
-	mutex_lock(&player->ctrl_lock);
+	guard(mutex)(&player->ctrl_lock);
 	ucontrol->value.iec958.status[0] = iec958->status[0];
 	ucontrol->value.iec958.status[1] = iec958->status[1];
 	ucontrol->value.iec958.status[2] = iec958->status[2];
 	ucontrol->value.iec958.status[3] = iec958->status[3];
-	mutex_unlock(&player->ctrl_lock);
 	return 0;
 }
 
@@ -591,23 +590,20 @@ static int uni_player_ctl_iec958_put(struct snd_kcontrol *kcontrol,
 	struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
 	struct uniperif *player = priv->dai_data.uni;
 	struct snd_aes_iec958 *iec958 =  &player->stream_settings.iec958;
-	unsigned long flags;
 
-	mutex_lock(&player->ctrl_lock);
+	guard(mutex)(&player->ctrl_lock);
 	iec958->status[0] = ucontrol->value.iec958.status[0];
 	iec958->status[1] = ucontrol->value.iec958.status[1];
 	iec958->status[2] = ucontrol->value.iec958.status[2];
 	iec958->status[3] = ucontrol->value.iec958.status[3];
 
-	spin_lock_irqsave(&player->irq_lock, flags);
-	if (player->substream && player->substream->runtime)
-		uni_player_set_channel_status(player,
-					      player->substream->runtime);
-	else
-		uni_player_set_channel_status(player, NULL);
-
-	spin_unlock_irqrestore(&player->irq_lock, flags);
-	mutex_unlock(&player->ctrl_lock);
+	scoped_guard(spinlock_irqsave, &player->irq_lock) {
+		if (player->substream && player->substream->runtime)
+			uni_player_set_channel_status(player,
+						      player->substream->runtime);
+		else
+			uni_player_set_channel_status(player, NULL);
+	}
 
 	return 0;
 }
@@ -642,9 +638,8 @@ static int snd_sti_clk_adjustment_get(struct snd_kcontrol *kcontrol,
 	struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
 	struct uniperif *player = priv->dai_data.uni;
 
-	mutex_lock(&player->ctrl_lock);
+	guard(mutex)(&player->ctrl_lock);
 	ucontrol->value.integer.value[0] = player->clk_adj;
-	mutex_unlock(&player->ctrl_lock);
 
 	return 0;
 }
@@ -661,12 +656,11 @@ static int snd_sti_clk_adjustment_put(struct snd_kcontrol *kcontrol,
 	    (ucontrol->value.integer.value[0] > UNIPERIF_PLAYER_CLK_ADJ_MAX))
 		return -EINVAL;
 
-	mutex_lock(&player->ctrl_lock);
+	guard(mutex)(&player->ctrl_lock);
 	player->clk_adj = ucontrol->value.integer.value[0];
 
 	if (player->mclk)
 		ret = uni_player_clk_set_rate(player, player->mclk);
-	mutex_unlock(&player->ctrl_lock);
 
 	return ret;
 }
@@ -693,12 +687,10 @@ static int uni_player_startup(struct snd_pcm_substream *substream,
 {
 	struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
 	struct uniperif *player = priv->dai_data.uni;
-	unsigned long flags;
 	int ret;
 
-	spin_lock_irqsave(&player->irq_lock, flags);
-	player->substream = substream;
-	spin_unlock_irqrestore(&player->irq_lock, flags);
+	scoped_guard(spinlock_irqsave, &player->irq_lock)
+		player->substream = substream;
 
 	player->clk_adj = 0;
 
@@ -734,11 +726,10 @@ static int uni_player_set_sysclk(struct snd_soc_dai *dai, int clk_id,
 	if (clk_id != 0)
 		return -EINVAL;
 
-	mutex_lock(&player->ctrl_lock);
+	guard(mutex)(&player->ctrl_lock);
 	ret = uni_player_clk_set_rate(player, freq);
 	if (!ret)
 		player->mclk = freq;
-	mutex_unlock(&player->ctrl_lock);
 
 	return ret;
 }
@@ -996,15 +987,13 @@ static void uni_player_shutdown(struct snd_pcm_substream *substream,
 {
 	struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
 	struct uniperif *player = priv->dai_data.uni;
-	unsigned long flags;
 
-	spin_lock_irqsave(&player->irq_lock, flags);
+	guard(spinlock_irqsave)(&player->irq_lock);
 	if (player->state != UNIPERIF_STATE_STOPPED)
 		/* Stop the player */
 		uni_player_stop(player);
 
 	player->substream = NULL;
-	spin_unlock_irqrestore(&player->irq_lock, flags);
 }
 
 static int uni_player_parse_dt_audio_glue(struct platform_device *pdev,
-- 
2.43.0


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

end of thread, other threads:[~2026-05-27 10:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-27 10:02 [PATCH 0/2] ASoC: sti: Use guard() for mutex & spin locks phucduc.bui
2026-05-27 10:02 ` [PATCH 1/2] ASoC: sti: uniperif_reader: Use guard() for " phucduc.bui
2026-05-27 10:02 ` [PATCH 2/2] ASoC: sti: uniperif_player: Use guard() for mutex & " phucduc.bui

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