From: phucduc.bui@gmail.com
To: Mark Brown <broonie@kernel.org>,
Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH 2/2] ASoC: sti: uniperif_player: Use guard() for mutex & spin locks
Date: Wed, 27 May 2026 17:02:06 +0700 [thread overview]
Message-ID: <20260527100206.26788-3-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260527100206.26788-1-phucduc.bui@gmail.com>
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
next prev parent reply other threads:[~2026-05-27 10:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-06-01 15:47 ` [PATCH 0/2] ASoC: sti: Use guard() for mutex & " Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260527100206.26788-3-phucduc.bui@gmail.com \
--to=phucduc.bui@gmail.com \
--cc=arnaud.pouliquen@foss.st.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.