]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ASoC: img: img-spdif-in: Use guard() for spin locks
authorbui duc phuc <phucduc.bui@gmail.com>
Wed, 10 Jun 2026 10:45:23 +0000 (17:45 +0700)
committerMark Brown <broonie@kernel.org>
Thu, 11 Jun 2026 19:43:32 +0000 (20:43 +0100)
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>
Link: https://patch.msgid.link/20260610104524.87166-2-phucduc.bui@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/img/img-spdif-in.c

index 82295e2508fa73da4f464531810a703d7d959c65..b630644f20ccbc8743fe3ac673995823dfdaf206 100644 (file)
@@ -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;
 }