]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: mtpav: Use guard() for spin locks
authorTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 15:00:21 +0000 (17:00 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 1 Sep 2025 11:53:35 +0000 (13:53 +0200)
Clean up the code using guard() for spin locks.

Merely code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250829150026.6379-11-tiwai@suse.de
sound/drivers/mtpav.c

index 91828f496738f6866996e8800255634e9d8be584..d31eadf4be5f83f08672b863bbe79e7ccb6fa95a 100644 (file)
@@ -304,11 +304,9 @@ static void snd_mtpav_output_write(struct snd_rawmidi_substream *substream)
 {
        struct mtpav *mtp_card = substream->rmidi->private_data;
        struct mtpav_port *portp = &mtp_card->ports[substream->number];
-       unsigned long flags;
 
-       spin_lock_irqsave(&mtp_card->spinlock, flags);
+       guard(spinlock_irqsave)(&mtp_card->spinlock);
        snd_mtpav_output_port_write(mtp_card, portp, substream);
-       spin_unlock_irqrestore(&mtp_card->spinlock, flags);
 }
 
 
@@ -334,14 +332,12 @@ static int snd_mtpav_input_open(struct snd_rawmidi_substream *substream)
 {
        struct mtpav *mtp_card = substream->rmidi->private_data;
        struct mtpav_port *portp = &mtp_card->ports[substream->number];
-       unsigned long flags;
 
-       spin_lock_irqsave(&mtp_card->spinlock, flags);
+       guard(spinlock_irqsave)(&mtp_card->spinlock);
        portp->mode |= MTPAV_MODE_INPUT_OPENED;
        portp->input = substream;
        if (mtp_card->share_irq++ == 0)
                snd_mtpav_mputreg(mtp_card, CREG, (SIGC_INTEN | SIGC_WRITE));   // enable pport interrupts
-       spin_unlock_irqrestore(&mtp_card->spinlock, flags);
        return 0;
 }
 
@@ -352,14 +348,12 @@ static int snd_mtpav_input_close(struct snd_rawmidi_substream *substream)
 {
        struct mtpav *mtp_card = substream->rmidi->private_data;
        struct mtpav_port *portp = &mtp_card->ports[substream->number];
-       unsigned long flags;
 
-       spin_lock_irqsave(&mtp_card->spinlock, flags);
+       guard(spinlock_irqsave)(&mtp_card->spinlock);
        portp->mode &= ~MTPAV_MODE_INPUT_OPENED;
        portp->input = NULL;
        if (--mtp_card->share_irq == 0)
                snd_mtpav_mputreg(mtp_card, CREG, 0);   // disable pport interrupts
-       spin_unlock_irqrestore(&mtp_card->spinlock, flags);
        return 0;
 }
 
@@ -370,15 +364,12 @@ static void snd_mtpav_input_trigger(struct snd_rawmidi_substream *substream, int
 {
        struct mtpav *mtp_card = substream->rmidi->private_data;
        struct mtpav_port *portp = &mtp_card->ports[substream->number];
-       unsigned long flags;
 
-       spin_lock_irqsave(&mtp_card->spinlock, flags);
+       guard(spinlock_irqsave)(&mtp_card->spinlock);
        if (up)
                portp->mode |= MTPAV_MODE_INPUT_TRIGGERED;
        else
                portp->mode &= ~MTPAV_MODE_INPUT_TRIGGERED;
-       spin_unlock_irqrestore(&mtp_card->spinlock, flags);
-
 }
 
 
@@ -388,11 +379,10 @@ static void snd_mtpav_input_trigger(struct snd_rawmidi_substream *substream, int
 
 static void snd_mtpav_output_timer(struct timer_list *t)
 {
-       unsigned long flags;
        struct mtpav *chip = timer_container_of(chip, t, timer);
        int p;
 
-       spin_lock_irqsave(&chip->spinlock, flags);
+       guard(spinlock_irqsave)(&chip->spinlock);
        /* reprogram timer */
        mod_timer(&chip->timer, 1 + jiffies);
        /* process each port */
@@ -401,7 +391,6 @@ static void snd_mtpav_output_timer(struct timer_list *t)
                if ((portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED) && portp->output)
                        snd_mtpav_output_port_write(chip, portp, portp->output);
        }
-       spin_unlock_irqrestore(&chip->spinlock, flags);
 }
 
 /* spinlock held! */
@@ -423,12 +412,10 @@ static int snd_mtpav_output_open(struct snd_rawmidi_substream *substream)
 {
        struct mtpav *mtp_card = substream->rmidi->private_data;
        struct mtpav_port *portp = &mtp_card->ports[substream->number];
-       unsigned long flags;
 
-       spin_lock_irqsave(&mtp_card->spinlock, flags);
+       guard(spinlock_irqsave)(&mtp_card->spinlock);
        portp->mode |= MTPAV_MODE_OUTPUT_OPENED;
        portp->output = substream;
-       spin_unlock_irqrestore(&mtp_card->spinlock, flags);
        return 0;
 };
 
@@ -439,12 +426,10 @@ static int snd_mtpav_output_close(struct snd_rawmidi_substream *substream)
 {
        struct mtpav *mtp_card = substream->rmidi->private_data;
        struct mtpav_port *portp = &mtp_card->ports[substream->number];
-       unsigned long flags;
 
-       spin_lock_irqsave(&mtp_card->spinlock, flags);
+       guard(spinlock_irqsave)(&mtp_card->spinlock);
        portp->mode &= ~MTPAV_MODE_OUTPUT_OPENED;
        portp->output = NULL;
-       spin_unlock_irqrestore(&mtp_card->spinlock, flags);
        return 0;
 };
 
@@ -455,21 +440,20 @@ static void snd_mtpav_output_trigger(struct snd_rawmidi_substream *substream, in
 {
        struct mtpav *mtp_card = substream->rmidi->private_data;
        struct mtpav_port *portp = &mtp_card->ports[substream->number];
-       unsigned long flags;
-
-       spin_lock_irqsave(&mtp_card->spinlock, flags);
-       if (up) {
-               if (! (portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED)) {
-                       if (mtp_card->istimer++ == 0)
-                               snd_mtpav_add_output_timer(mtp_card);
-                       portp->mode |= MTPAV_MODE_OUTPUT_TRIGGERED;
+
+       scoped_guard(spinlock_irqsave, &mtp_card->spinlock) {
+               if (up) {
+                       if ((portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED)) {
+                               if (mtp_card->istimer++ == 0)
+                                       snd_mtpav_add_output_timer(mtp_card);
+                               portp->mode |= MTPAV_MODE_OUTPUT_TRIGGERED;
+                       }
+               } else {
+                       portp->mode &= ~MTPAV_MODE_OUTPUT_TRIGGERED;
+                       if (--mtp_card->istimer == 0)
+                               snd_mtpav_remove_output_timer(mtp_card);
                }
-       } else {
-               portp->mode &= ~MTPAV_MODE_OUTPUT_TRIGGERED;
-               if (--mtp_card->istimer == 0)
-                       snd_mtpav_remove_output_timer(mtp_card);
        }
-       spin_unlock_irqrestore(&mtp_card->spinlock, flags);
 
        if (up)
                snd_mtpav_output_write(substream);
@@ -550,9 +534,8 @@ static irqreturn_t snd_mtpav_irqh(int irq, void *dev_id)
 {
        struct mtpav *mcard = dev_id;
 
-       spin_lock(&mcard->spinlock);
+       guard(spinlock)(&mcard->spinlock);
        snd_mtpav_read_bytes(mcard);
-       spin_unlock(&mcard->spinlock);
        return IRQ_HANDLED;
 }
 
@@ -658,12 +641,10 @@ static int snd_mtpav_get_RAWMIDI(struct mtpav *mcard)
 static void snd_mtpav_free(struct snd_card *card)
 {
        struct mtpav *crd = card->private_data;
-       unsigned long flags;
 
-       spin_lock_irqsave(&crd->spinlock, flags);
+       guard(spinlock_irqsave)(&crd->spinlock);
        if (crd->istimer > 0)
                snd_mtpav_remove_output_timer(crd);
-       spin_unlock_irqrestore(&crd->spinlock, flags);
 }
 
 /*