diff options
| author | bui duc phuc <phucduc.bui@gmail.com> | 2026-05-15 18:24:56 +0700 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2026-05-22 13:36:22 +0100 |
| commit | b212cb00168c3b0f6e63777e961c34e91ca6d53c (patch) | |
| tree | bd10b5eec816f442fdde1a2368bada904cfab0b7 /sound | |
| parent | dabf5b45b18cb249bbe57a6aaa173e155d247f08 (diff) | |
| download | linux-next-history-b212cb00168c3b0f6e63777e961c34e91ca6d53c.tar.gz | |
ASoC: stm: stm32_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 <phucduc.bui@gmail.com>
Link: https://patch.msgid.link/20260515112458.34378-3-phucduc.bui@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound')
| -rw-r--r-- | sound/soc/stm/stm32_i2s.c | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/sound/soc/stm/stm32_i2s.c b/sound/soc/stm/stm32_i2s.c index 6ca21780f21d4..ae9e25657f3fe 100644 --- a/sound/soc/stm/stm32_i2s.c +++ b/sound/soc/stm/stm32_i2s.c @@ -615,10 +615,10 @@ static irqreturn_t stm32_i2s_isr(int irq, void *devid) if (flags & I2S_SR_TIFRE) dev_dbg(&pdev->dev, "Frame error\n"); - spin_lock(&i2s->irq_lock); - if (err && i2s->substream) - snd_pcm_stop_xrun(i2s->substream); - spin_unlock(&i2s->irq_lock); + scoped_guard(spinlock, &i2s->irq_lock) { + if (err && i2s->substream) + snd_pcm_stop_xrun(i2s->substream); + } return IRQ_HANDLED; } @@ -905,12 +905,10 @@ static int stm32_i2s_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) { struct stm32_i2s_data *i2s = snd_soc_dai_get_drvdata(cpu_dai); - unsigned long flags; int ret; - spin_lock_irqsave(&i2s->irq_lock, flags); - i2s->substream = substream; - spin_unlock_irqrestore(&i2s->irq_lock, flags); + scoped_guard(spinlock_irqsave, &i2s->irq_lock) + i2s->substream = substream; if ((i2s->fmt & SND_SOC_DAIFMT_FORMAT_MASK) != SND_SOC_DAIFMT_DSP_A) snd_pcm_hw_constraint_single(substream->runtime, @@ -982,19 +980,19 @@ static int stm32_i2s_trigger(struct snd_pcm_substream *substream, int cmd, regmap_write_bits(i2s->regmap, STM32_I2S_IFCR_REG, I2S_IFCR_MASK, I2S_IFCR_MASK); - spin_lock(&i2s->lock_fd); - i2s->refcount++; - if (playback_flg) { - ier = I2S_IER_UDRIE; - } else { - ier = I2S_IER_OVRIE; + scoped_guard(spinlock, &i2s->lock_fd) { + i2s->refcount++; + if (playback_flg) { + ier = I2S_IER_UDRIE; + } else { + ier = I2S_IER_OVRIE; - if (STM32_I2S_IS_MASTER(i2s) && i2s->refcount == 1) - /* dummy write to gate bus clocks */ - regmap_write(i2s->regmap, - STM32_I2S_TXDR_REG, 0); + if (STM32_I2S_IS_MASTER(i2s) && i2s->refcount == 1) + /* dummy write to gate bus clocks */ + regmap_write(i2s->regmap, + STM32_I2S_TXDR_REG, 0); + } } - spin_unlock(&i2s->lock_fd); if (STM32_I2S_IS_SLAVE(i2s)) ier |= I2S_IER_TIFREIE; @@ -1016,21 +1014,18 @@ static int stm32_i2s_trigger(struct snd_pcm_substream *substream, int cmd, I2S_IER_OVRIE, (unsigned int)~I2S_IER_OVRIE); - spin_lock(&i2s->lock_fd); - i2s->refcount--; - if (i2s->refcount) { - spin_unlock(&i2s->lock_fd); - break; - } + scoped_guard(spinlock, &i2s->lock_fd) { + i2s->refcount--; + if (i2s->refcount) + return 0; - ret = regmap_update_bits(i2s->regmap, STM32_I2S_CR1_REG, - I2S_CR1_SPE, 0); - if (ret < 0) { - dev_err(cpu_dai->dev, "Error %d disabling I2S\n", ret); - spin_unlock(&i2s->lock_fd); - return ret; + ret = regmap_update_bits(i2s->regmap, STM32_I2S_CR1_REG, + I2S_CR1_SPE, 0); + if (ret < 0) { + dev_err(cpu_dai->dev, "Error %d disabling I2S\n", ret); + return ret; + } } - spin_unlock(&i2s->lock_fd); cfg1_mask = I2S_CFG1_RXDMAEN | I2S_CFG1_TXDMAEN; regmap_update_bits(i2s->regmap, STM32_I2S_CFG1_REG, @@ -1047,7 +1042,6 @@ static void stm32_i2s_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) { struct stm32_i2s_data *i2s = snd_soc_dai_get_drvdata(cpu_dai); - unsigned long flags; clk_disable_unprepare(i2s->i2sclk); @@ -1059,9 +1053,8 @@ static void stm32_i2s_shutdown(struct snd_pcm_substream *substream, if (!i2s->i2smclk && i2s->put_i2s_clk_rate) i2s->put_i2s_clk_rate(i2s); - spin_lock_irqsave(&i2s->irq_lock, flags); - i2s->substream = NULL; - spin_unlock_irqrestore(&i2s->irq_lock, flags); + scoped_guard(spinlock_irqsave, &i2s->irq_lock) + i2s->substream = NULL; } static int stm32_i2s_dai_probe(struct snd_soc_dai *cpu_dai) |
