Skip to contentSkip to conversation

ASoC: img: Use guard() for spin locks

PATCH In review [email protected] 2 participants 4 messages Jun 10 – Jun 12

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ASoC: img: Use guard() for spin locks

From: bui duc phuc <[email protected]>

Hi all,

This series converts spinlock handling in several IMG ASoC drivers to use guard() helpers.
All patches are straightforward cleanups with no functional change intended.

Compile-tested only.

Best regards,
Phuc

bui duc phuc (2):
ASoC: img: img-spdif-in: Use guard() for spin locks
ASoC: img: img-spdif-out: Use guard() for spin locks

 sound/soc/img/img-spdif-in.c  | 70 +++++++++--------------------------
 sound/soc/img/img-spdif-out.c | 16 ++------
 2 files changed, 21 insertions(+), 65 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 ASoC: img: img-spdif-in: Use guard() for spin locks

From: bui duc phuc <[email protected]>

Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.

---
 sound/soc/img/img-spdif-in.c | 70 +++++++++---------------------------
 1 file changed, 17 insertions(+), 53 deletions(-)
sound/soc/img/img-spdif-in.c +17 -53
index 82295e2508fa..b630644f20cc 100644
@@ -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;
 }
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 ASoC: img: img-spdif-out: Use guard() for spin locks

In reply to [email protected]

From: bui duc phuc <[email protected]>

Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.

---
 sound/soc/img/img-spdif-out.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
sound/soc/img/img-spdif-out.c +4 -12
index 52f696219ef4..39a37e4830d8 100644
@@ -135,9 +135,8 @@ static int img_spdif_out_get_status(struct snd_kcontrol *kcontrol,
 	struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
 	struct img_spdif_out *spdif = snd_soc_dai_get_drvdata(cpu_dai);
 	u32 reg;
-	unsigned long flags;
 
-	spin_lock_irqsave(&spdif->lock, flags);
+	guard(spinlock_irqsave)(&spdif->lock);
 
 	reg = img_spdif_out_readl(spdif, IMG_SPDIF_OUT_CSL);
 	ucontrol->value.iec958.status[0] = reg & 0xff;
@@ -150,8 +149,6 @@ static int img_spdif_out_get_status(struct snd_kcontrol *kcontrol,
 		(reg & IMG_SPDIF_OUT_CSH_UV_CSH_MASK) >>
 		IMG_SPDIF_OUT_CSH_UV_CSH_SHIFT;
 
-	spin_unlock_irqrestore(&spdif->lock, flags);
-
 	return 0;
 }
 
@@ -161,14 +158,13 @@ static int img_spdif_out_set_status(struct snd_kcontrol *kcontrol,
 	struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
 	struct img_spdif_out *spdif = snd_soc_dai_get_drvdata(cpu_dai);
 	u32 reg;
-	unsigned long flags;
 
 	reg = ((u32)ucontrol->value.iec958.status[3] << 24);
 	reg |= ((u32)ucontrol->value.iec958.status[2] << 16);
 	reg |= ((u32)ucontrol->value.iec958.status[1] << 8);
 	reg |= (u32)ucontrol->value.iec958.status[0];
 
-	spin_lock_irqsave(&spdif->lock, flags);
+	guard(spinlock_irqsave)(&spdif->lock);
 
 	img_spdif_out_writel(spdif, reg, IMG_SPDIF_OUT_CSL);
 
@@ -178,8 +174,6 @@ static int img_spdif_out_set_status(struct snd_kcontrol *kcontrol,
 			IMG_SPDIF_OUT_CSH_UV_CSH_SHIFT;
 	img_spdif_out_writel(spdif, reg, IMG_SPDIF_OUT_CSH_UV);
 
-	spin_unlock_irqrestore(&spdif->lock, flags);
-
 	return 0;
 }
 
@@ -205,7 +199,6 @@ static int img_spdif_out_trigger(struct snd_pcm_substream *substream, int cmd,
 {
 	struct img_spdif_out *spdif = snd_soc_dai_get_drvdata(dai);
 	u32 reg;
-	unsigned long flags;
 
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
@@ -218,9 +211,8 @@ static int img_spdif_out_trigger(struct snd_pcm_substream *substream, int cmd,
 	case SNDRV_PCM_TRIGGER_STOP:
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-		spin_lock_irqsave(&spdif->lock, flags);
-		img_spdif_out_reset(spdif);
-		spin_unlock_irqrestore(&spdif->lock, flags);
+		scoped_guard(spinlock_irqsave, &spdif->lock)
+			img_spdif_out_reset(spdif);
 		break;
 	default:
 		return -EINVAL;
Signature · 1 line
2.43.0
maintainer
#3 lore raw
In reply to [email protected]
Quoted 4 lines · On Wed, 10 Jun 2026 17:45:22 +0700, [email protected] wrote:

ASoC: img: Use guard() for spin locks

From: bui duc phuc <[email protected]>

Quoted 8 lines

Hi all,

This series converts spinlock handling in several IMG ASoC drivers to use guard() helpers.
All patches are straightforward cleanups with no functional change intended.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.2

Thanks!

[1/2] ASoC: img: img-spdif-in: Use guard() for spin locks

      https://git.kernel.org/broonie/sound/c/131e13f35f16
[2/2] ASoC: img: img-spdif-out: Use guard() for spin locks
      https://git.kernel.org/broonie/sound/c/4fbf9d7a1c4f

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark