From: bui duc phuc Date: Thu, 23 Apr 2026 12:56:42 +0000 (+0700) Subject: ASoC: samsung: i2s: Use guard() for spin locks X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d08517b5c67e1612e9320a6b2b74dbc576e85d7;p=thirdparty%2Flinux.git ASoC: samsung: i2s: Use guard() for spin locks Clean up the code using guard() for spin locks. Merely code refactoring, and no behavior change. Signed-off-by: bui duc phuc Link: https://patch.msgid.link/20260423125646.156599-2-phucduc.bui@gmail.com Signed-off-by: Mark Brown --- diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c index 140907a41a70d..f80f697a5d55d 100644 --- a/sound/soc/samsung/i2s.c +++ b/sound/soc/samsung/i2s.c @@ -510,14 +510,13 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int rfs, unsigned int cdcon_mask = 1 << i2s_regs->cdclkcon_off; unsigned int rsrc_mask = 1 << i2s_regs->rclksrc_off; u32 mod, mask, val = 0; - unsigned long flags; int ret = 0; pm_runtime_get_sync(dai->dev); - spin_lock_irqsave(&priv->lock, flags); - mod = readl(priv->addr + I2SMOD); - spin_unlock_irqrestore(&priv->lock, flags); + scoped_guard(spinlock_irqsave, &priv->lock) + mod = readl(priv->addr + I2SMOD); + switch (clk_id) { case SAMSUNG_I2S_OPCLK: @@ -612,11 +611,11 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int rfs, goto err; } - spin_lock_irqsave(&priv->lock, flags); - mod = readl(priv->addr + I2SMOD); - mod = (mod & ~mask) | val; - writel(mod, priv->addr + I2SMOD); - spin_unlock_irqrestore(&priv->lock, flags); + scoped_guard(spinlock_irqsave, &priv->lock) { + mod = readl(priv->addr + I2SMOD); + mod = (mod & ~mask) | val; + writel(mod, priv->addr + I2SMOD); + } done: pm_runtime_put(dai->dev); @@ -729,7 +728,6 @@ static int i2s_hw_params(struct snd_pcm_substream *substream, struct i2s_dai *i2s = to_info(dai); u32 mod, mask = 0, val = 0; struct clk *rclksrc; - unsigned long flags; WARN_ON(!pm_runtime_active(dai->dev)); @@ -801,11 +799,11 @@ static int i2s_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - spin_lock_irqsave(&priv->lock, flags); - mod = readl(priv->addr + I2SMOD); - mod = (mod & ~mask) | val; - writel(mod, priv->addr + I2SMOD); - spin_unlock_irqrestore(&priv->lock, flags); + scoped_guard(spinlock_irqsave, &priv->lock) { + mod = readl(priv->addr + I2SMOD); + mod = (mod & ~mask) | val; + writel(mod, priv->addr + I2SMOD); + } snd_soc_dai_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture); @@ -825,11 +823,10 @@ static int i2s_startup(struct snd_pcm_substream *substream, struct samsung_i2s_priv *priv = snd_soc_dai_get_drvdata(dai); struct i2s_dai *i2s = to_info(dai); struct i2s_dai *other = get_other_dai(i2s); - unsigned long flags; pm_runtime_get_sync(dai->dev); - spin_lock_irqsave(&priv->pcm_lock, flags); + guard(spinlock_irqsave)(&priv->pcm_lock); i2s->mode |= DAI_OPENED; @@ -841,8 +838,6 @@ static int i2s_startup(struct snd_pcm_substream *substream, if (!any_active(i2s) && (priv->quirks & QUIRK_NEED_RSTCLR)) writel(CON_RSTCLR, i2s->priv->addr + I2SCON); - spin_unlock_irqrestore(&priv->pcm_lock, flags); - return 0; } @@ -852,21 +847,18 @@ static void i2s_shutdown(struct snd_pcm_substream *substream, struct samsung_i2s_priv *priv = snd_soc_dai_get_drvdata(dai); struct i2s_dai *i2s = to_info(dai); struct i2s_dai *other = get_other_dai(i2s); - unsigned long flags; - - spin_lock_irqsave(&priv->pcm_lock, flags); - i2s->mode &= ~DAI_OPENED; - i2s->mode &= ~DAI_MANAGER; + scoped_guard(spinlock_irqsave, &priv->pcm_lock) { + i2s->mode &= ~DAI_OPENED; + i2s->mode &= ~DAI_MANAGER; - if (is_opened(other)) - other->mode |= DAI_MANAGER; + if (is_opened(other)) + other->mode |= DAI_MANAGER; - /* Reset any constraint on RFS and BFS */ - i2s->rfs = 0; - i2s->bfs = 0; - - spin_unlock_irqrestore(&priv->pcm_lock, flags); + /* Reset any constraint on RFS and BFS */ + i2s->rfs = 0; + i2s->bfs = 0; + } pm_runtime_put(dai->dev); } @@ -939,7 +931,6 @@ static int i2s_trigger(struct snd_pcm_substream *substream, int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); struct i2s_dai *i2s = to_info(snd_soc_rtd_to_cpu(rtd, 0)); - unsigned long flags; switch (cmd) { case SNDRV_PCM_TRIGGER_START: @@ -950,37 +941,31 @@ static int i2s_trigger(struct snd_pcm_substream *substream, if (priv->fixup_early) priv->fixup_early(substream, dai); - spin_lock_irqsave(&priv->lock, flags); + scoped_guard(spinlock_irqsave, &priv->lock) { + if (config_setup(i2s)) + return -EINVAL; - if (config_setup(i2s)) { - spin_unlock_irqrestore(&priv->lock, flags); - return -EINVAL; - } + if (priv->fixup_late) + priv->fixup_late(substream, dai); - if (priv->fixup_late) - priv->fixup_late(substream, dai); - - if (capture) - i2s_rxctrl(i2s, 1); - else - i2s_txctrl(i2s, 1); - - spin_unlock_irqrestore(&priv->lock, flags); + if (capture) + i2s_rxctrl(i2s, 1); + else + i2s_txctrl(i2s, 1); + } break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: - spin_lock_irqsave(&priv->lock, flags); - - if (capture) { - i2s_rxctrl(i2s, 0); - i2s_fifo(i2s, FIC_RXFLUSH); - } else { - i2s_txctrl(i2s, 0); - i2s_fifo(i2s, FIC_TXFLUSH); + scoped_guard(spinlock_irqsave, &priv->lock) { + if (capture) { + i2s_rxctrl(i2s, 0); + i2s_fifo(i2s, FIC_RXFLUSH); + } else { + i2s_txctrl(i2s, 0); + i2s_fifo(i2s, FIC_TXFLUSH); + } } - - spin_unlock_irqrestore(&priv->lock, flags); pm_runtime_put(dai->dev); break; } @@ -1056,7 +1041,6 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai) struct samsung_i2s_priv *priv = snd_soc_dai_get_drvdata(dai); struct i2s_dai *i2s = to_info(dai); struct i2s_dai *other = get_other_dai(i2s); - unsigned long flags; pm_runtime_get_sync(dai->dev); @@ -1079,13 +1063,13 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai) i2s->rfs = 0; i2s->bfs = 0; - spin_lock_irqsave(&priv->lock, flags); - i2s_txctrl(i2s, 0); - i2s_rxctrl(i2s, 0); - i2s_fifo(i2s, FIC_TXFLUSH); - i2s_fifo(other, FIC_TXFLUSH); - i2s_fifo(i2s, FIC_RXFLUSH); - spin_unlock_irqrestore(&priv->lock, flags); + scoped_guard(spinlock_irqsave, &priv->lock) { + i2s_txctrl(i2s, 0); + i2s_rxctrl(i2s, 0); + i2s_fifo(i2s, FIC_TXFLUSH); + i2s_fifo(other, FIC_TXFLUSH); + i2s_fifo(i2s, FIC_RXFLUSH); + } /* Gate CDCLK by default */ if (!is_opened(other)) @@ -1100,15 +1084,13 @@ static int samsung_i2s_dai_remove(struct snd_soc_dai *dai) { struct samsung_i2s_priv *priv = snd_soc_dai_get_drvdata(dai); struct i2s_dai *i2s = to_info(dai); - unsigned long flags; pm_runtime_get_sync(dai->dev); if (!is_secondary(i2s)) { if (priv->quirks & QUIRK_NEED_RSTCLR) { - spin_lock_irqsave(&priv->lock, flags); - writel(0, priv->addr + I2SCON); - spin_unlock_irqrestore(&priv->lock, flags); + scoped_guard(spinlock_irqsave, &priv->lock) + writel(0, priv->addr + I2SCON); } }