From: bui duc phuc Date: Fri, 15 May 2026 11:24:58 +0000 (+0700) Subject: ASoC: stm: stm32_spdifrx: Use guard() for spin locks X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f0d573c32592ae5a3fc718a03e040d532402d84;p=thirdparty%2Fkernel%2Flinux.git ASoC: stm: stm32_spdifrx: 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/20260515112458.34378-5-phucduc.bui@gmail.com Signed-off-by: Mark Brown --- 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); }