From: phucduc.bui@gmail.com
To: Olivier Moysan <olivier.moysan@foss.st.com>,
Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>,
Mark Brown <broonie@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
linux-sound@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH 4/4] ASoC: stm: stm32_spdifrx: Use guard() for spin locks
Date: Wed, 13 May 2026 17:43:29 +0700 [thread overview]
Message-ID: <20260513104329.81592-5-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260513104329.81592-1-phucduc.bui@gmail.com>
From: bui duc phuc <phucduc.bui@gmail.com>
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>
---
sound/soc/stm/stm32_spdifrx.c | 44 +++++++++++++----------------------
1 file changed, 16 insertions(+), 28 deletions(-)
diff --git a/sound/soc/stm/stm32_spdifrx.c b/sound/soc/stm/stm32_spdifrx.c
index 57b711c44278..2f83ca989e68 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);
}
--
2.43.0
prev parent reply other threads:[~2026-05-13 10:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 10:43 [PATCH 0/4] ASoC: stm: Use guard() for mutex & spin locks phucduc.bui
2026-05-13 10:43 ` [PATCH 1/4] ASoC: stm: stm32_adfsdm: Use guard() for mutex locks phucduc.bui
2026-05-13 10:43 ` [PATCH 2/4] ASoC: stm: stm32_i2s: Use guard() for spin locks phucduc.bui
2026-05-13 10:43 ` [PATCH 3/4] ASoC: stm: stm32_sai_sub: Use guard() for mutex & " phucduc.bui
2026-05-13 10:43 ` phucduc.bui [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260513104329.81592-5-phucduc.bui@gmail.com \
--to=phucduc.bui@gmail.com \
--cc=alexandre.torgue@foss.st.com \
--cc=arnaud.pouliquen@foss.st.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=olivier.moysan@foss.st.com \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox