ASoC: sti: Use guard() for mutex & spin locks
Subsystems (3)
cover ASoC: sti: Use guard() for mutex & spin locks
From: bui duc phuc <[email protected]>
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(-)
Signature · 1 line
2.43.0
PATCH 1/2 ASoC: sti: uniperif_reader: Use guard() for spin locks
From: bui duc phuc <[email protected]>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
---
Compile-tested only.
sound/soc/sti/uniperif_reader.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
sound/soc/sti/uniperif_reader.c +7 -13
@@ -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 = {
Signature · 1 line
2.43.0
PATCH 2/2 ASoC: sti: uniperif_player: Use guard() for mutex & spin locks
In reply to [email protected]From: bui duc phuc <[email protected]>
Clean up the code using guard() for mutex & spin locks. Merely code refactoring, and no behavior change.
---
Compile-tested only.
sound/soc/sti/uniperif_player.c | 73 ++++++++++++++------------------- 1 file changed, 31 insertions(+), 42 deletions(-)
sound/soc/sti/uniperif_player.c +31 -42
@@ -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,
Signature · 1 line
2.43.0
Mark Brown
maintainerQuoted 4 lines · On Wed, 27 May 2026 17:02:04 +0700, [email protected] wrote:
ASoC: sti: Use
guard()for mutex & spin locksFrom: bui duc phuc <[email protected]>
Quoted 8 lines
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.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.2
Thanks!
[1/2] ASoC: sti: uniperif_reader: Use guard() for spin locks
https://git.kernel.org/broonie/sound/c/205cc2a7eff0 [2/2] ASoC: sti: uniperif_player: Use guard() for mutex & spin locks https://git.kernel.org/broonie/sound/c/96166a8def74
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark