All of lore.kernel.org
 help / color / mirror / Atom feed
From: phucduc.bui@gmail.com
To: Mark Brown <broonie@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH 1/2] ASoC: img: img-spdif-in: Use guard() for spin locks
Date: Wed, 10 Jun 2026 17:45:23 +0700	[thread overview]
Message-ID: <20260610104524.87166-2-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260610104524.87166-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/img/img-spdif-in.c | 70 +++++++++---------------------------
 1 file changed, 17 insertions(+), 53 deletions(-)

diff --git a/sound/soc/img/img-spdif-in.c b/sound/soc/img/img-spdif-in.c
index 82295e2508fa..b630644f20cc 100644
--- a/sound/soc/img/img-spdif-in.c
+++ b/sound/soc/img/img-spdif-in.c
@@ -179,7 +179,7 @@ static int img_spdif_in_do_clkgen_single(struct img_spdif_in *spdif,
 		unsigned int rate)
 {
 	unsigned int nom, hld;
-	unsigned long flags, clk_rate;
+	unsigned long clk_rate;
 	int ret = 0;
 	u32 reg;
 
@@ -196,19 +196,15 @@ static int img_spdif_in_do_clkgen_single(struct img_spdif_in *spdif,
 	reg |= (hld << IMG_SPDIF_IN_CLKGEN_HLD_SHIFT) &
 		IMG_SPDIF_IN_CLKGEN_HLD_MASK;
 
-	spin_lock_irqsave(&spdif->lock, flags);
+	guard(spinlock_irqsave)(&spdif->lock);
 
-	if (spdif->active) {
-		spin_unlock_irqrestore(&spdif->lock, flags);
+	if (spdif->active)
 		return -EBUSY;
-	}
 
 	img_spdif_in_writel(spdif, reg, IMG_SPDIF_IN_CLKGEN);
 
 	spdif->single_freq = rate;
 
-	spin_unlock_irqrestore(&spdif->lock, flags);
-
 	return 0;
 }
 
@@ -216,7 +212,7 @@ static int img_spdif_in_do_clkgen_multi(struct img_spdif_in *spdif,
 		unsigned int multi_freqs[])
 {
 	unsigned int nom, hld, rate, max_rate = 0;
-	unsigned long flags, clk_rate;
+	unsigned long clk_rate;
 	int i, ret = 0;
 	u32 reg, trk_reg, temp_regs[IMG_SPDIF_IN_NUM_ACLKGEN];
 
@@ -242,12 +238,10 @@ static int img_spdif_in_do_clkgen_multi(struct img_spdif_in *spdif,
 		temp_regs[i] = reg;
 	}
 
-	spin_lock_irqsave(&spdif->lock, flags);
+	guard(spinlock_irqsave)(&spdif->lock);
 
-	if (spdif->active) {
-		spin_unlock_irqrestore(&spdif->lock, flags);
+	if (spdif->active)
 		return -EBUSY;
-	}
 
 	trk_reg = spdif->trk << IMG_SPDIF_IN_ACLKGEN_TRK_SHIFT;
 
@@ -262,8 +256,6 @@ static int img_spdif_in_do_clkgen_multi(struct img_spdif_in *spdif,
 	spdif->multi_freqs[2] = multi_freqs[2];
 	spdif->multi_freqs[3] = multi_freqs[3];
 
-	spin_unlock_irqrestore(&spdif->lock, flags);
-
 	return 0;
 }
 
@@ -323,9 +315,8 @@ static int img_spdif_in_get_multi_freq(struct snd_kcontrol *kcontrol,
 {
 	struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
 	struct img_spdif_in *spdif = snd_soc_dai_get_drvdata(cpu_dai);
-	unsigned long flags;
 
-	spin_lock_irqsave(&spdif->lock, flags);
+	guard(spinlock_irqsave)(&spdif->lock);
 	if (spdif->multi_freq) {
 		ucontrol->value.integer.value[0] = spdif->multi_freqs[0];
 		ucontrol->value.integer.value[1] = spdif->multi_freqs[1];
@@ -337,7 +328,6 @@ static int img_spdif_in_get_multi_freq(struct snd_kcontrol *kcontrol,
 		ucontrol->value.integer.value[2] = 0;
 		ucontrol->value.integer.value[3] = 0;
 	}
-	spin_unlock_irqrestore(&spdif->lock, flags);
 
 	return 0;
 }
@@ -349,7 +339,6 @@ static int img_spdif_in_set_multi_freq(struct snd_kcontrol *kcontrol,
 	struct img_spdif_in *spdif = snd_soc_dai_get_drvdata(cpu_dai);
 	unsigned int multi_freqs[IMG_SPDIF_IN_NUM_ACLKGEN];
 	bool multi_freq;
-	unsigned long flags;
 
 	if ((ucontrol->value.integer.value[0] == 0) &&
 			(ucontrol->value.integer.value[1] == 0) &&
@@ -367,17 +356,13 @@ static int img_spdif_in_set_multi_freq(struct snd_kcontrol *kcontrol,
 	if (multi_freq)
 		return img_spdif_in_do_clkgen_multi(spdif, multi_freqs);
 
-	spin_lock_irqsave(&spdif->lock, flags);
+	guard(spinlock_irqsave)(&spdif->lock);
 
-	if (spdif->active) {
-		spin_unlock_irqrestore(&spdif->lock, flags);
+	if (spdif->active)
 		return -EBUSY;
-	}
 
 	spdif->multi_freq = false;
 
-	spin_unlock_irqrestore(&spdif->lock, flags);
-
 	return 0;
 }
 
@@ -399,9 +384,8 @@ static int img_spdif_in_get_lock_freq(struct snd_kcontrol *kcontrol,
 	struct img_spdif_in *spdif = snd_soc_dai_get_drvdata(cpu_dai);
 	u32 reg;
 	int i;
-	unsigned long flags;
 
-	spin_lock_irqsave(&spdif->lock, flags);
+	guard(spinlock_irqsave)(&spdif->lock);
 
 	reg = img_spdif_in_readl(spdif, IMG_SPDIF_IN_STATUS);
 	if (reg & IMG_SPDIF_IN_STATUS_LOCK_MASK) {
@@ -416,8 +400,6 @@ static int img_spdif_in_get_lock_freq(struct snd_kcontrol *kcontrol,
 		uc->value.integer.value[0] = 0;
 	}
 
-	spin_unlock_irqrestore(&spdif->lock, flags);
-
 	return 0;
 }
 
@@ -448,16 +430,13 @@ static int img_spdif_in_set_trk(struct snd_kcontrol *kcontrol,
 {
 	struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
 	struct img_spdif_in *spdif = snd_soc_dai_get_drvdata(cpu_dai);
-	unsigned long flags;
 	int i;
 	u32 reg;
 
-	spin_lock_irqsave(&spdif->lock, flags);
+	guard(spinlock_irqsave)(&spdif->lock);
 
-	if (spdif->active) {
-		spin_unlock_irqrestore(&spdif->lock, flags);
+	if (spdif->active)
 		return -EBUSY;
-	}
 
 	spdif->trk = ucontrol->value.integer.value[0];
 
@@ -474,8 +453,6 @@ static int img_spdif_in_set_trk(struct snd_kcontrol *kcontrol,
 		img_spdif_in_aclkgen_writel(spdif, i);
 	}
 
-	spin_unlock_irqrestore(&spdif->lock, flags);
-
 	return 0;
 }
 
@@ -506,15 +483,12 @@ static int img_spdif_in_set_lock_acquire(struct snd_kcontrol *kcontrol,
 {
 	struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
 	struct img_spdif_in *spdif = snd_soc_dai_get_drvdata(cpu_dai);
-	unsigned long flags;
 	u32 reg;
 
-	spin_lock_irqsave(&spdif->lock, flags);
+	guard(spinlock_irqsave)(&spdif->lock);
 
-	if (spdif->active) {
-		spin_unlock_irqrestore(&spdif->lock, flags);
+	if (spdif->active)
 		return -EBUSY;
-	}
 
 	spdif->lock_acquire = ucontrol->value.integer.value[0];
 
@@ -524,8 +498,6 @@ static int img_spdif_in_set_lock_acquire(struct snd_kcontrol *kcontrol,
 		IMG_SPDIF_IN_CTL_LOCKHI_MASK;
 	img_spdif_in_writel(spdif, reg, IMG_SPDIF_IN_CTL);
 
-	spin_unlock_irqrestore(&spdif->lock, flags);
-
 	return 0;
 }
 
@@ -545,15 +517,12 @@ static int img_spdif_in_set_lock_release(struct snd_kcontrol *kcontrol,
 {
 	struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
 	struct img_spdif_in *spdif = snd_soc_dai_get_drvdata(cpu_dai);
-	unsigned long flags;
 	u32 reg;
 
-	spin_lock_irqsave(&spdif->lock, flags);
+	guard(spinlock_irqsave)(&spdif->lock);
 
-	if (spdif->active) {
-		spin_unlock_irqrestore(&spdif->lock, flags);
+	if (spdif->active)
 		return -EBUSY;
-	}
 
 	spdif->lock_release = ucontrol->value.integer.value[0];
 
@@ -563,8 +532,6 @@ static int img_spdif_in_set_lock_release(struct snd_kcontrol *kcontrol,
 		IMG_SPDIF_IN_CTL_LOCKLO_MASK;
 	img_spdif_in_writel(spdif, reg, IMG_SPDIF_IN_CTL);
 
-	spin_unlock_irqrestore(&spdif->lock, flags);
-
 	return 0;
 }
 
@@ -625,12 +592,11 @@ static struct snd_kcontrol_new img_spdif_in_controls[] = {
 static int img_spdif_in_trigger(struct snd_pcm_substream *substream, int cmd,
 	struct snd_soc_dai *dai)
 {
-	unsigned long flags;
 	struct img_spdif_in *spdif = snd_soc_dai_get_drvdata(dai);
 	int ret = 0;
 	u32 reg;
 
-	spin_lock_irqsave(&spdif->lock, flags);
+	guard(spinlock_irqsave)(&spdif->lock);
 
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
@@ -657,8 +623,6 @@ static int img_spdif_in_trigger(struct snd_pcm_substream *substream, int cmd,
 		ret = -EINVAL;
 	}
 
-	spin_unlock_irqrestore(&spdif->lock, flags);
-
 	return ret;
 }
 
-- 
2.43.0


  reply	other threads:[~2026-06-10 10:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10 10:45 [PATCH 0/2] ASoC: img: Use guard() for spin locks phucduc.bui
2026-06-10 10:45 ` phucduc.bui [this message]
2026-06-10 10:45 ` [PATCH 2/2] ASoC: img: img-spdif-out: " phucduc.bui

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=20260610104524.87166-2-phucduc.bui@gmail.com \
    --to=phucduc.bui@gmail.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.