mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 10:09:10 +02:00
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
This commit is contained in:
commit
6d2359028c
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user