linux-sound.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Subject: [PATCH 33/61] ALSA: fm801: Use guard() for spin locks
Date: Fri, 29 Aug 2025 16:43:08 +0200	[thread overview]
Message-ID: <20250829144342.4290-34-tiwai@suse.de> (raw)
In-Reply-To: <20250829144342.4290-1-tiwai@suse.de>

Clean up the code using guard() for spin locks.

Merely code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/fm801.c | 71 ++++++++++++++++++++---------------------------
 1 file changed, 30 insertions(+), 41 deletions(-)

diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index cf40bd06b734..4ca992449ea3 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -279,16 +279,14 @@ static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg,
 				 unsigned short mask, unsigned short value)
 {
 	int change;
-	unsigned long flags;
 	unsigned short old, new;
 
-	spin_lock_irqsave(&chip->reg_lock, flags);
+	guard(spinlock_irqsave)(&chip->reg_lock);
 	old = fm801_ioread16(chip, reg);
 	new = (old & ~mask) | value;
 	change = old != new;
 	if (change)
 		fm801_iowrite16(chip, reg, new);
-	spin_unlock_irqrestore(&chip->reg_lock, flags);
 	return change;
 }
 
@@ -393,7 +391,7 @@ static int snd_fm801_playback_trigger(struct snd_pcm_substream *substream,
 {
 	struct fm801 *chip = snd_pcm_substream_chip(substream);
 
-	spin_lock(&chip->reg_lock);
+	guard(spinlock)(&chip->reg_lock);
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
 		chip->ply_ctrl &= ~(FM801_BUF1_LAST |
@@ -414,12 +412,10 @@ static int snd_fm801_playback_trigger(struct snd_pcm_substream *substream,
 		chip->ply_ctrl &= ~FM801_PAUSE;
 		break;
 	default:
-		spin_unlock(&chip->reg_lock);
 		snd_BUG();
 		return -EINVAL;
 	}
 	fm801_writew(chip, PLY_CTRL, chip->ply_ctrl);
-	spin_unlock(&chip->reg_lock);
 	return 0;
 }
 
@@ -428,7 +424,7 @@ static int snd_fm801_capture_trigger(struct snd_pcm_substream *substream,
 {
 	struct fm801 *chip = snd_pcm_substream_chip(substream);
 
-	spin_lock(&chip->reg_lock);
+	guard(spinlock)(&chip->reg_lock);
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
 		chip->cap_ctrl &= ~(FM801_BUF1_LAST |
@@ -449,12 +445,10 @@ static int snd_fm801_capture_trigger(struct snd_pcm_substream *substream,
 		chip->cap_ctrl &= ~FM801_PAUSE;
 		break;
 	default:
-		spin_unlock(&chip->reg_lock);
 		snd_BUG();
 		return -EINVAL;
 	}
 	fm801_writew(chip, CAP_CTRL, chip->cap_ctrl);
-	spin_unlock(&chip->reg_lock);
 	return 0;
 }
 
@@ -465,7 +459,7 @@ static int snd_fm801_playback_prepare(struct snd_pcm_substream *substream)
 
 	chip->ply_size = snd_pcm_lib_buffer_bytes(substream);
 	chip->ply_count = snd_pcm_lib_period_bytes(substream);
-	spin_lock_irq(&chip->reg_lock);
+	guard(spinlock_irq)(&chip->reg_lock);
 	chip->ply_ctrl &= ~(FM801_START | FM801_16BIT |
 			     FM801_STEREO | FM801_RATE_MASK |
 			     FM801_CHANNELS_MASK);
@@ -487,7 +481,6 @@ static int snd_fm801_playback_prepare(struct snd_pcm_substream *substream)
 	fm801_writel(chip, PLY_BUF1, chip->ply_buffer);
 	fm801_writel(chip, PLY_BUF2,
 		     chip->ply_buffer + (chip->ply_count % chip->ply_size));
-	spin_unlock_irq(&chip->reg_lock);
 	return 0;
 }
 
@@ -498,7 +491,7 @@ static int snd_fm801_capture_prepare(struct snd_pcm_substream *substream)
 
 	chip->cap_size = snd_pcm_lib_buffer_bytes(substream);
 	chip->cap_count = snd_pcm_lib_period_bytes(substream);
-	spin_lock_irq(&chip->reg_lock);
+	guard(spinlock_irq)(&chip->reg_lock);
 	chip->cap_ctrl &= ~(FM801_START | FM801_16BIT |
 			     FM801_STEREO | FM801_RATE_MASK);
 	if (snd_pcm_format_width(runtime->format) == 16)
@@ -514,7 +507,6 @@ static int snd_fm801_capture_prepare(struct snd_pcm_substream *substream)
 	fm801_writel(chip, CAP_BUF1, chip->cap_buffer);
 	fm801_writel(chip, CAP_BUF2,
 		     chip->cap_buffer + (chip->cap_count % chip->cap_size));
-	spin_unlock_irq(&chip->reg_lock);
 	return 0;
 }
 
@@ -525,13 +517,12 @@ static snd_pcm_uframes_t snd_fm801_playback_pointer(struct snd_pcm_substream *su
 
 	if (!(chip->ply_ctrl & FM801_START))
 		return 0;
-	spin_lock(&chip->reg_lock);
+	guard(spinlock)(&chip->reg_lock);
 	ptr = chip->ply_pos + (chip->ply_count - 1) - fm801_readw(chip, PLY_COUNT);
 	if (fm801_readw(chip, IRQ_STATUS) & FM801_IRQ_PLAYBACK) {
 		ptr += chip->ply_count;
 		ptr %= chip->ply_size;
 	}
-	spin_unlock(&chip->reg_lock);
 	return bytes_to_frames(substream->runtime, ptr);
 }
 
@@ -542,13 +533,12 @@ static snd_pcm_uframes_t snd_fm801_capture_pointer(struct snd_pcm_substream *sub
 
 	if (!(chip->cap_ctrl & FM801_START))
 		return 0;
-	spin_lock(&chip->reg_lock);
+	guard(spinlock)(&chip->reg_lock);
 	ptr = chip->cap_pos + (chip->cap_count - 1) - fm801_readw(chip, CAP_COUNT);
 	if (fm801_readw(chip, IRQ_STATUS) & FM801_IRQ_CAPTURE) {
 		ptr += chip->cap_count;
 		ptr %= chip->cap_size;
 	}
-	spin_unlock(&chip->reg_lock);
 	return bytes_to_frames(substream->runtime, ptr);
 }
 
@@ -565,31 +555,31 @@ static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id)
 	/* ack first */
 	fm801_writew(chip, IRQ_STATUS, status);
 	if (chip->pcm && (status & FM801_IRQ_PLAYBACK) && chip->playback_substream) {
-		spin_lock(&chip->reg_lock);
-		chip->ply_buf++;
-		chip->ply_pos += chip->ply_count;
-		chip->ply_pos %= chip->ply_size;
-		tmp = chip->ply_pos + chip->ply_count;
-		tmp %= chip->ply_size;
-		if (chip->ply_buf & 1)
-			fm801_writel(chip, PLY_BUF1, chip->ply_buffer + tmp);
-		else
-			fm801_writel(chip, PLY_BUF2, chip->ply_buffer + tmp);
-		spin_unlock(&chip->reg_lock);
+		scoped_guard(spinlock, &chip->reg_lock) {
+			chip->ply_buf++;
+			chip->ply_pos += chip->ply_count;
+			chip->ply_pos %= chip->ply_size;
+			tmp = chip->ply_pos + chip->ply_count;
+			tmp %= chip->ply_size;
+			if (chip->ply_buf & 1)
+				fm801_writel(chip, PLY_BUF1, chip->ply_buffer + tmp);
+			else
+				fm801_writel(chip, PLY_BUF2, chip->ply_buffer + tmp);
+		}
 		snd_pcm_period_elapsed(chip->playback_substream);
 	}
 	if (chip->pcm && (status & FM801_IRQ_CAPTURE) && chip->capture_substream) {
-		spin_lock(&chip->reg_lock);
-		chip->cap_buf++;
-		chip->cap_pos += chip->cap_count;
-		chip->cap_pos %= chip->cap_size;
-		tmp = chip->cap_pos + chip->cap_count;
-		tmp %= chip->cap_size;
-		if (chip->cap_buf & 1)
-			fm801_writel(chip, CAP_BUF1, chip->cap_buffer + tmp);
-		else
-			fm801_writel(chip, CAP_BUF2, chip->cap_buffer + tmp);
-		spin_unlock(&chip->reg_lock);
+		scoped_guard(spinlock, &chip->reg_lock) {
+			chip->cap_buf++;
+			chip->cap_pos += chip->cap_count;
+			chip->cap_pos %= chip->cap_size;
+			tmp = chip->cap_pos + chip->cap_count;
+			tmp %= chip->cap_size;
+			if (chip->cap_buf & 1)
+				fm801_writel(chip, CAP_BUF1, chip->cap_buffer + tmp);
+			else
+				fm801_writel(chip, CAP_BUF2, chip->cap_buffer + tmp);
+		}
 		snd_pcm_period_elapsed(chip->capture_substream);
 	}
 	if (chip->rmidi && (status & FM801_IRQ_MPU))
@@ -924,10 +914,9 @@ static int snd_fm801_get_double(struct snd_kcontrol *kcontrol,
 	int invert = (kcontrol->private_value >> 24) & 0xff;
 	long *value = ucontrol->value.integer.value;
 
-	spin_lock_irq(&chip->reg_lock);
+	guard(spinlock_irq)(&chip->reg_lock);
 	value[0] = (fm801_ioread16(chip, reg) >> shift_left) & mask;
 	value[1] = (fm801_ioread16(chip, reg) >> shift_right) & mask;
-	spin_unlock_irq(&chip->reg_lock);
 	if (invert) {
 		value[0] = mask - value[0];
 		value[1] = mask - value[1];
-- 
2.50.1


  parent reply	other threads:[~2025-08-29 14:45 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-29 14:42 [PATCH 00/61] ALSA: Use auto-cleanup for PCI drivers Takashi Iwai
2025-08-29 14:42 ` [PATCH 01/61] ALSA: ac97: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 02/61] ALSA: ac97: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 03/61] ALSA: ali5451: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 04/61] ALSA: azt3328: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 05/61] ALSA: ens137x: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 06/61] ALSA: ens137x: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 07/61] ALSA: als300: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 08/61] ALSA: als4000: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 09/61] ALSA: ad1889: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 10/61] ALSA: atiixp: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 11/61] ALSA: atiixp: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 12/61] ALSA: aw2: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 13/61] ALSA: aw2: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 14/61] ALSA: bt87x: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 15/61] ALSA: ca0106: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 16/61] ALSA: cmipci: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 17/61] ALSA: cmipci: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 18/61] ALSA: cs4281: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 19/61] ALSA: cs46xx: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 20/61] ALSA: cs46xx: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 21/61] ALSA: cs5535audio: " Takashi Iwai
2025-08-29 14:42 ` [PATCH 22/61] ALSA: ctxfi: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 23/61] ALSA: ctxfi: Use guard() for spin locks Takashi Iwai
2025-08-29 14:42 ` [PATCH 24/61] ALSA: echoaudio: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 25/61] ALSA: echoaudio: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 26/61] ALSA: emu10k1: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 27/61] ALSA: emu10k1: Use guard() for emu1010 FPGA locking Takashi Iwai
2025-08-29 14:43 ` [PATCH 28/61] ALSA: emu10k1: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 29/61] ALSA: emu10k1x: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 30/61] ALSA: es1938: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 31/61] ALSA: es1968: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 32/61] ALSA: es1968: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` Takashi Iwai [this message]
2025-08-29 14:43 ` [PATCH 34/61] ALSA: ice1712: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 35/61] ALSA: ice1712: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 36/61] ALSA: intel8x0: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 37/61] ALSA: korg1212: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 38/61] ALSA: korg1212: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 39/61] ALSA: lola: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 40/61] ALSA: lola: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 41/61] ALSA: lx6464es: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 42/61] ALSA: maestro3: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 43/61] ALSA: mixart: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 44/61] ALSA: nm256: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 45/61] ALSA: nm256: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 46/61] ALSA: oxygen: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 47/61] ALSA: oxygen: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 48/61] ALSA: pcxhr: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 49/61] ALSA: rme32: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 50/61] ALSA: rme96: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 51/61] ALSA: hdsp: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 52/61] ALSA: hdspm: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 53/61] ALSA: rme9652: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 54/61] ALSA: sis7019: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 55/61] ALSA: sis7019: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 56/61] ALSA: sonicvibes: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 57/61] ALSA: trident: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 58/61] ALSA: trident: Use guard() for spin locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 59/61] ALSA: via82xx: " Takashi Iwai
2025-08-29 14:43 ` [PATCH 60/61] ALSA: vx222: Use guard() for mutex locks Takashi Iwai
2025-08-29 14:43 ` [PATCH 61/61] ALSA: ymfpci: Use guard() for spin locks Takashi Iwai

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=20250829144342.4290-34-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=linux-sound@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).