diff options
| author | Mark Brown <broonie@kernel.org> | 2026-05-22 13:36:26 +0100 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2026-05-22 13:36:26 +0100 |
| commit | 4de16aa84229011a3f4139b37f7525ee1804c771 (patch) | |
| tree | 4c78560a3b2a2aca551f436c1d59ef863244af56 /sound | |
| parent | 5404599c3292a12dfc6a3b604cebb5d51064f553 (diff) | |
| parent | 3f0d573c32592ae5a3fc718a03e040d532402d84 (diff) | |
| download | linux-next-history-4de16aa84229011a3f4139b37f7525ee1804c771.tar.gz | |
ASoC: stm: Use guard() for mutex & spin locks
phucduc.bui@gmail.com <phucduc.bui@gmail.com> says:
This series converts mutex and spinlock handling in the STM drivers
to use guard() helpers.
The changes are code cleanup only and should have no functional impact.
Link: https://patch.msgid.link/20260515112458.34378-1-phucduc.bui@gmail.com
Diffstat (limited to 'sound')
| -rw-r--r-- | sound/soc/stm/stm32_adfsdm.c | 10 | ||||
| -rw-r--r-- | sound/soc/stm/stm32_i2s.c | 65 | ||||
| -rw-r--r-- | sound/soc/stm/stm32_sai_sub.c | 29 | ||||
| -rw-r--r-- | sound/soc/stm/stm32_spdifrx.c | 44 |
4 files changed, 59 insertions, 89 deletions
diff --git a/sound/soc/stm/stm32_adfsdm.c b/sound/soc/stm/stm32_adfsdm.c index 0f6d32814c222..a585cb9fc011a 100644 --- a/sound/soc/stm/stm32_adfsdm.c +++ b/sound/soc/stm/stm32_adfsdm.c @@ -62,12 +62,11 @@ static void stm32_adfsdm_shutdown(struct snd_pcm_substream *substream, { struct stm32_adfsdm_priv *priv = snd_soc_dai_get_drvdata(dai); - mutex_lock(&priv->lock); + guard(mutex)(&priv->lock); if (priv->iio_active) { iio_channel_stop_all_cb(priv->iio_cb); priv->iio_active = false; } - mutex_unlock(&priv->lock); } static int stm32_adfsdm_dai_prepare(struct snd_pcm_substream *substream, @@ -76,7 +75,7 @@ static int stm32_adfsdm_dai_prepare(struct snd_pcm_substream *substream, struct stm32_adfsdm_priv *priv = snd_soc_dai_get_drvdata(dai); int ret; - mutex_lock(&priv->lock); + guard(mutex)(&priv->lock); if (priv->iio_active) { iio_channel_stop_all_cb(priv->iio_cb); priv->iio_active = false; @@ -88,7 +87,7 @@ static int stm32_adfsdm_dai_prepare(struct snd_pcm_substream *substream, if (ret < 0) { dev_err(dai->dev, "%s: Failed to set %d sampling rate\n", __func__, substream->runtime->rate); - goto out; + return ret; } if (!priv->iio_active) { @@ -100,9 +99,6 @@ static int stm32_adfsdm_dai_prepare(struct snd_pcm_substream *substream, __func__, ret); } -out: - mutex_unlock(&priv->lock); - return ret; } 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) diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c index 3e82fa90e719a..ea9e8bddd63f0 100644 --- a/sound/soc/stm/stm32_sai_sub.c +++ b/sound/soc/stm/stm32_sai_sub.c @@ -280,9 +280,8 @@ static int snd_pcm_iec958_get(struct snd_kcontrol *kcontrol, { struct stm32_sai_sub_data *sai = snd_kcontrol_chip(kcontrol); - mutex_lock(&sai->ctrl_lock); + guard(mutex)(&sai->ctrl_lock); memcpy(uctl->value.iec958.status, sai->iec958.status, 4); - mutex_unlock(&sai->ctrl_lock); return 0; } @@ -292,9 +291,8 @@ static int snd_pcm_iec958_put(struct snd_kcontrol *kcontrol, { struct stm32_sai_sub_data *sai = snd_kcontrol_chip(kcontrol); - mutex_lock(&sai->ctrl_lock); + guard(mutex)(&sai->ctrl_lock); memcpy(sai->iec958.status, uctl->value.iec958.status, 4); - mutex_unlock(&sai->ctrl_lock); return 0; } @@ -658,10 +656,10 @@ static irqreturn_t stm32_sai_isr(int irq, void *devid) status = SNDRV_PCM_STATE_XRUN; } - spin_lock(&sai->irq_lock); - if (status != SNDRV_PCM_STATE_RUNNING && sai->substream) - snd_pcm_stop_xrun(sai->substream); - spin_unlock(&sai->irq_lock); + scoped_guard(spinlock, &sai->irq_lock) { + if (status != SNDRV_PCM_STATE_RUNNING && sai->substream) + snd_pcm_stop_xrun(sai->substream); + } return IRQ_HANDLED; } @@ -894,11 +892,9 @@ static int stm32_sai_startup(struct snd_pcm_substream *substream, { struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); int imr, cr2, ret; - unsigned long flags; - spin_lock_irqsave(&sai->irq_lock, flags); - sai->substream = substream; - spin_unlock_irqrestore(&sai->irq_lock, flags); + scoped_guard(spinlock_irqsave, &sai->irq_lock) + sai->substream = substream; if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) { snd_pcm_hw_constraint_mask64(substream->runtime, @@ -1083,7 +1079,7 @@ static void stm32_sai_set_iec958_status(struct stm32_sai_sub_data *sai, return; /* Force the sample rate according to runtime rate */ - mutex_lock(&sai->ctrl_lock); + guard(mutex)(&sai->ctrl_lock); switch (runtime->rate) { case 22050: sai->iec958.status[3] = IEC958_AES3_CON_FS_22050; @@ -1116,7 +1112,6 @@ static void stm32_sai_set_iec958_status(struct stm32_sai_sub_data *sai, sai->iec958.status[3] = IEC958_AES3_CON_FS_NOTID; break; } - mutex_unlock(&sai->ctrl_lock); } static int stm32_sai_configure_clock(struct snd_soc_dai *cpu_dai, @@ -1284,7 +1279,6 @@ static void stm32_sai_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) { struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); - unsigned long flags; stm32_sai_sub_reg_up(sai, STM_SAI_IMR_REGX, SAI_XIMR_MASK, 0); @@ -1298,9 +1292,8 @@ static void stm32_sai_shutdown(struct snd_pcm_substream *substream, if (!sai->sai_mclk && sai->put_sai_ck_rate) sai->put_sai_ck_rate(sai); - spin_lock_irqsave(&sai->irq_lock, flags); - sai->substream = NULL; - spin_unlock_irqrestore(&sai->irq_lock, flags); + scoped_guard(spinlock_irqsave, &sai->irq_lock) + sai->substream = NULL; } static int stm32_sai_pcm_new(struct snd_soc_pcm_runtime *rtd, diff --git a/sound/soc/stm/stm32_spdifrx.c b/sound/soc/stm/stm32_spdifrx.c index 57b711c442784..2f83ca989e688 100644 --- a/sound/soc/stm/stm32_spdifrx.c +++ b/sound/soc/stm/stm32_spdifrx.c @@ -322,7 +322,6 @@ static void stm32_spdifrx_dma_ctrl_stop(struct stm32_spdifrx_data *spdifrx) static int stm32_spdifrx_start_sync(struct stm32_spdifrx_data *spdifrx) { int cr, cr_mask, imr, ret; - unsigned long flags; /* Enable IRQs */ imr = SPDIFRX_IMR_IFEIE | SPDIFRX_IMR_SYNCDIE | SPDIFRX_IMR_PERRIE; @@ -330,7 +329,7 @@ static int stm32_spdifrx_start_sync(struct stm32_spdifrx_data *spdifrx) if (ret) return ret; - spin_lock_irqsave(&spdifrx->lock, flags); + guard(spinlock_irqsave)(&spdifrx->lock); spdifrx->refcount++; @@ -365,22 +364,17 @@ static int stm32_spdifrx_start_sync(struct stm32_spdifrx_data *spdifrx) "Failed to start synchronization\n"); } - spin_unlock_irqrestore(&spdifrx->lock, flags); - return ret; } static void stm32_spdifrx_stop(struct stm32_spdifrx_data *spdifrx) { int cr, cr_mask, reg; - unsigned long flags; - spin_lock_irqsave(&spdifrx->lock, flags); + guard(spinlock_irqsave)(&spdifrx->lock); - if (--spdifrx->refcount) { - spin_unlock_irqrestore(&spdifrx->lock, flags); + if (--spdifrx->refcount) return; - } cr = SPDIFRX_CR_SPDIFENSET(SPDIFRX_SPDIFEN_DISABLE); cr_mask = SPDIFRX_CR_SPDIFEN_MASK | SPDIFRX_CR_RXDMAEN; @@ -396,8 +390,6 @@ static void stm32_spdifrx_stop(struct stm32_spdifrx_data *spdifrx) /* dummy read to clear CSRNE and RXNE in status register */ regmap_read(spdifrx->regmap, STM32_SPDIFRX_DR, ®); regmap_read(spdifrx->regmap, STM32_SPDIFRX_CSR, ®); - - spin_unlock_irqrestore(&spdifrx->lock, flags); } static int stm32_spdifrx_dma_ctrl_register(struct device *dev, @@ -744,19 +736,19 @@ static irqreturn_t stm32_spdifrx_isr(int irq, void *devid) return IRQ_HANDLED; } - spin_lock(&spdifrx->irq_lock); - if (spdifrx->substream) - snd_pcm_stop(spdifrx->substream, - SNDRV_PCM_STATE_DISCONNECTED); - spin_unlock(&spdifrx->irq_lock); + scoped_guard(spinlock, &spdifrx->irq_lock) { + if (spdifrx->substream) + snd_pcm_stop(spdifrx->substream, + SNDRV_PCM_STATE_DISCONNECTED); + } return IRQ_HANDLED; } - spin_lock(&spdifrx->irq_lock); - if (err_xrun && spdifrx->substream) - snd_pcm_stop_xrun(spdifrx->substream); - spin_unlock(&spdifrx->irq_lock); + scoped_guard(spinlock, &spdifrx->irq_lock) { + if (err_xrun && spdifrx->substream) + snd_pcm_stop_xrun(spdifrx->substream); + } return IRQ_HANDLED; } @@ -765,12 +757,10 @@ static int stm32_spdifrx_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) { struct stm32_spdifrx_data *spdifrx = snd_soc_dai_get_drvdata(cpu_dai); - unsigned long flags; int ret; - spin_lock_irqsave(&spdifrx->irq_lock, flags); - spdifrx->substream = substream; - spin_unlock_irqrestore(&spdifrx->irq_lock, flags); + scoped_guard(spinlock_irqsave, &spdifrx->irq_lock) + spdifrx->substream = substream; ret = clk_prepare_enable(spdifrx->kclk); if (ret) @@ -846,11 +836,9 @@ static void stm32_spdifrx_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) { struct stm32_spdifrx_data *spdifrx = snd_soc_dai_get_drvdata(cpu_dai); - unsigned long flags; - spin_lock_irqsave(&spdifrx->irq_lock, flags); - spdifrx->substream = NULL; - spin_unlock_irqrestore(&spdifrx->irq_lock, flags); + scoped_guard(spinlock_irqsave, &spdifrx->irq_lock) + spdifrx->substream = NULL; clk_disable_unprepare(spdifrx->kclk); } |
