Skip to content

Commit 6d23590

Browse files
committed
ASoC: sti: Use guard() for mutex & spin locks
phucduc.bui@gmail.com <phucduc.bui@gmail.com> says: 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. Link: https://patch.msgid.link/20260527100206.26788-1-phucduc.bui@gmail.com
2 parents 054f183 + 96166a8 commit 6d23590

2 files changed

Lines changed: 38 additions & 55 deletions

File tree

sound/soc/sti/uniperif_player.c

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ static irqreturn_t uni_player_irq_handler(int irq, void *dev_id)
6565
unsigned int status;
6666
unsigned int tmp;
6767

68-
spin_lock(&player->irq_lock);
68+
guard(spinlock)(&player->irq_lock);
6969
if (!player->substream)
70-
goto irq_spin_unlock;
70+
return ret;
7171

7272
snd_pcm_stream_lock(player->substream);
73-
if (player->state == UNIPERIF_STATE_STOPPED)
74-
goto stream_unlock;
73+
if (player->state == UNIPERIF_STATE_STOPPED) {
74+
snd_pcm_stream_unlock(player->substream);
75+
return ret;
76+
}
7577

7678
/* Get interrupt status & clear them immediately */
7779
status = GET_UNIPERIF_ITS(player);
@@ -116,7 +118,8 @@ static irqreturn_t uni_player_irq_handler(int irq, void *dev_id)
116118
dev_err(player->dev,
117119
"unexpected Underflow recovering\n");
118120
ret = -EPERM;
119-
goto stream_unlock;
121+
snd_pcm_stream_unlock(player->substream);
122+
return ret;
120123
}
121124
/* Read the underflow recovery duration */
122125
tmp = GET_UNIPERIF_STATUS_1_UNDERFLOW_DURATION(player);
@@ -143,10 +146,7 @@ static irqreturn_t uni_player_irq_handler(int irq, void *dev_id)
143146
ret = IRQ_HANDLED;
144147
}
145148

146-
stream_unlock:
147149
snd_pcm_stream_unlock(player->substream);
148-
irq_spin_unlock:
149-
spin_unlock(&player->irq_lock);
150150

151151
return ret;
152152
}
@@ -363,10 +363,10 @@ static int uni_player_prepare_iec958(struct uniperif *player,
363363

364364
SET_UNIPERIF_CTRL_ZERO_STUFF_HW(player);
365365

366-
mutex_lock(&player->ctrl_lock);
367366
/* Update the channel status */
368-
uni_player_set_channel_status(player, runtime);
369-
mutex_unlock(&player->ctrl_lock);
367+
scoped_guard(mutex, &player->ctrl_lock)
368+
uni_player_set_channel_status(player, runtime);
369+
370370

371371
/* Clear the user validity user bits */
372372
SET_UNIPERIF_USER_VALIDITY_VALIDITY_LR(player, 0);
@@ -546,11 +546,11 @@ static int uni_player_prepare_tdm(struct uniperif *player,
546546

547547
/* set unip clk rate (not done vai set_sysclk ops) */
548548
freq = runtime->rate * tdm_frame_size * 8;
549-
mutex_lock(&player->ctrl_lock);
550-
ret = uni_player_clk_set_rate(player, freq);
551-
if (!ret)
552-
player->mclk = freq;
553-
mutex_unlock(&player->ctrl_lock);
549+
scoped_guard(mutex, &player->ctrl_lock) {
550+
ret = uni_player_clk_set_rate(player, freq);
551+
if (!ret)
552+
player->mclk = freq;
553+
}
554554

555555
return 0;
556556
}
@@ -575,12 +575,11 @@ static int uni_player_ctl_iec958_get(struct snd_kcontrol *kcontrol,
575575
struct uniperif *player = priv->dai_data.uni;
576576
struct snd_aes_iec958 *iec958 = &player->stream_settings.iec958;
577577

578-
mutex_lock(&player->ctrl_lock);
578+
guard(mutex)(&player->ctrl_lock);
579579
ucontrol->value.iec958.status[0] = iec958->status[0];
580580
ucontrol->value.iec958.status[1] = iec958->status[1];
581581
ucontrol->value.iec958.status[2] = iec958->status[2];
582582
ucontrol->value.iec958.status[3] = iec958->status[3];
583-
mutex_unlock(&player->ctrl_lock);
584583
return 0;
585584
}
586585

@@ -591,23 +590,20 @@ static int uni_player_ctl_iec958_put(struct snd_kcontrol *kcontrol,
591590
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
592591
struct uniperif *player = priv->dai_data.uni;
593592
struct snd_aes_iec958 *iec958 = &player->stream_settings.iec958;
594-
unsigned long flags;
595593

596-
mutex_lock(&player->ctrl_lock);
594+
guard(mutex)(&player->ctrl_lock);
597595
iec958->status[0] = ucontrol->value.iec958.status[0];
598596
iec958->status[1] = ucontrol->value.iec958.status[1];
599597
iec958->status[2] = ucontrol->value.iec958.status[2];
600598
iec958->status[3] = ucontrol->value.iec958.status[3];
601599

602-
spin_lock_irqsave(&player->irq_lock, flags);
603-
if (player->substream && player->substream->runtime)
604-
uni_player_set_channel_status(player,
605-
player->substream->runtime);
606-
else
607-
uni_player_set_channel_status(player, NULL);
608-
609-
spin_unlock_irqrestore(&player->irq_lock, flags);
610-
mutex_unlock(&player->ctrl_lock);
600+
scoped_guard(spinlock_irqsave, &player->irq_lock) {
601+
if (player->substream && player->substream->runtime)
602+
uni_player_set_channel_status(player,
603+
player->substream->runtime);
604+
else
605+
uni_player_set_channel_status(player, NULL);
606+
}
611607

612608
return 0;
613609
}
@@ -642,9 +638,8 @@ static int snd_sti_clk_adjustment_get(struct snd_kcontrol *kcontrol,
642638
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
643639
struct uniperif *player = priv->dai_data.uni;
644640

645-
mutex_lock(&player->ctrl_lock);
641+
guard(mutex)(&player->ctrl_lock);
646642
ucontrol->value.integer.value[0] = player->clk_adj;
647-
mutex_unlock(&player->ctrl_lock);
648643

649644
return 0;
650645
}
@@ -661,12 +656,11 @@ static int snd_sti_clk_adjustment_put(struct snd_kcontrol *kcontrol,
661656
(ucontrol->value.integer.value[0] > UNIPERIF_PLAYER_CLK_ADJ_MAX))
662657
return -EINVAL;
663658

664-
mutex_lock(&player->ctrl_lock);
659+
guard(mutex)(&player->ctrl_lock);
665660
player->clk_adj = ucontrol->value.integer.value[0];
666661

667662
if (player->mclk)
668663
ret = uni_player_clk_set_rate(player, player->mclk);
669-
mutex_unlock(&player->ctrl_lock);
670664

671665
return ret;
672666
}
@@ -693,12 +687,10 @@ static int uni_player_startup(struct snd_pcm_substream *substream,
693687
{
694688
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
695689
struct uniperif *player = priv->dai_data.uni;
696-
unsigned long flags;
697690
int ret;
698691

699-
spin_lock_irqsave(&player->irq_lock, flags);
700-
player->substream = substream;
701-
spin_unlock_irqrestore(&player->irq_lock, flags);
692+
scoped_guard(spinlock_irqsave, &player->irq_lock)
693+
player->substream = substream;
702694

703695
player->clk_adj = 0;
704696

@@ -734,11 +726,10 @@ static int uni_player_set_sysclk(struct snd_soc_dai *dai, int clk_id,
734726
if (clk_id != 0)
735727
return -EINVAL;
736728

737-
mutex_lock(&player->ctrl_lock);
729+
guard(mutex)(&player->ctrl_lock);
738730
ret = uni_player_clk_set_rate(player, freq);
739731
if (!ret)
740732
player->mclk = freq;
741-
mutex_unlock(&player->ctrl_lock);
742733

743734
return ret;
744735
}
@@ -996,15 +987,13 @@ static void uni_player_shutdown(struct snd_pcm_substream *substream,
996987
{
997988
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
998989
struct uniperif *player = priv->dai_data.uni;
999-
unsigned long flags;
1000990

1001-
spin_lock_irqsave(&player->irq_lock, flags);
991+
guard(spinlock_irqsave)(&player->irq_lock);
1002992
if (player->state != UNIPERIF_STATE_STOPPED)
1003993
/* Stop the player */
1004994
uni_player_stop(player);
1005995

1006996
player->substream = NULL;
1007-
spin_unlock_irqrestore(&player->irq_lock, flags);
1008997
}
1009998

1010999
static int uni_player_parse_dt_audio_glue(struct platform_device *pdev,

sound/soc/sti/uniperif_reader.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ static irqreturn_t uni_reader_irq_handler(int irq, void *dev_id)
4646
struct uniperif *reader = dev_id;
4747
unsigned int status;
4848

49-
spin_lock(&reader->irq_lock);
49+
guard(spinlock)(&reader->irq_lock);
5050
if (!reader->substream)
51-
goto irq_spin_unlock;
51+
return ret;
5252

5353
snd_pcm_stream_lock(reader->substream);
5454
if (reader->state == UNIPERIF_STATE_STOPPED) {
5555
/* Unexpected IRQ: do nothing */
5656
dev_warn(reader->dev, "unexpected IRQ\n");
57-
goto stream_unlock;
57+
snd_pcm_stream_unlock(reader->substream);
58+
return ret;
5859
}
5960

6061
/* Get interrupt status & clear them immediately */
@@ -70,10 +71,7 @@ static irqreturn_t uni_reader_irq_handler(int irq, void *dev_id)
7071
ret = IRQ_HANDLED;
7172
}
7273

73-
stream_unlock:
7474
snd_pcm_stream_unlock(reader->substream);
75-
irq_spin_unlock:
76-
spin_unlock(&reader->irq_lock);
7775

7876
return ret;
7977
}
@@ -355,12 +353,10 @@ static int uni_reader_startup(struct snd_pcm_substream *substream,
355353
{
356354
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
357355
struct uniperif *reader = priv->dai_data.uni;
358-
unsigned long flags;
359356
int ret;
360357

361-
spin_lock_irqsave(&reader->irq_lock, flags);
362-
reader->substream = substream;
363-
spin_unlock_irqrestore(&reader->irq_lock, flags);
358+
scoped_guard(spinlock_irqsave, &reader->irq_lock)
359+
reader->substream = substream;
364360

365361
if (!UNIPERIF_TYPE_IS_TDM(reader))
366362
return 0;
@@ -386,15 +382,13 @@ static void uni_reader_shutdown(struct snd_pcm_substream *substream,
386382
{
387383
struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
388384
struct uniperif *reader = priv->dai_data.uni;
389-
unsigned long flags;
390385

391-
spin_lock_irqsave(&reader->irq_lock, flags);
386+
guard(spinlock_irqsave)(&reader->irq_lock);
392387
if (reader->state != UNIPERIF_STATE_STOPPED) {
393388
/* Stop the reader */
394389
uni_reader_stop(reader);
395390
}
396391
reader->substream = NULL;
397-
spin_unlock_irqrestore(&reader->irq_lock, flags);
398392
}
399393

400394
static const struct snd_soc_dai_ops uni_reader_dai_ops = {

0 commit comments

Comments
 (0)