Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: firewire: dice: Use guard() for spin locks

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

Merely code refactoring, and no behavior change.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250828132802.9032-13-tiwai@suse.de

+21 -54
+10 -27
sound/firewire/dice/dice-hwdep.c
··· 55 55 poll_table *wait) 56 56 { 57 57 struct snd_dice *dice = hwdep->private_data; 58 - __poll_t events; 59 58 60 59 poll_wait(file, &dice->hwdep_wait, wait); 61 60 62 - spin_lock_irq(&dice->lock); 61 + guard(spinlock_irq)(&dice->lock); 63 62 if (dice->dev_lock_changed || dice->notification_bits != 0) 64 - events = EPOLLIN | EPOLLRDNORM; 63 + return EPOLLIN | EPOLLRDNORM; 65 64 else 66 - events = 0; 67 - spin_unlock_irq(&dice->lock); 68 - 69 - return events; 65 + return 0; 70 66 } 71 67 72 68 static int hwdep_get_info(struct snd_dice *dice, void __user *arg) ··· 86 90 87 91 static int hwdep_lock(struct snd_dice *dice) 88 92 { 89 - int err; 90 - 91 - spin_lock_irq(&dice->lock); 93 + guard(spinlock_irq)(&dice->lock); 92 94 93 95 if (dice->dev_lock_count == 0) { 94 96 dice->dev_lock_count = -1; 95 - err = 0; 97 + return 0; 96 98 } else { 97 - err = -EBUSY; 99 + return -EBUSY; 98 100 } 99 - 100 - spin_unlock_irq(&dice->lock); 101 - 102 - return err; 103 101 } 104 102 105 103 static int hwdep_unlock(struct snd_dice *dice) 106 104 { 107 - int err; 108 - 109 - spin_lock_irq(&dice->lock); 105 + guard(spinlock_irq)(&dice->lock); 110 106 111 107 if (dice->dev_lock_count == -1) { 112 108 dice->dev_lock_count = 0; 113 - err = 0; 109 + return 0; 114 110 } else { 115 - err = -EBADFD; 111 + return -EBADFD; 116 112 } 117 - 118 - spin_unlock_irq(&dice->lock); 119 - 120 - return err; 121 113 } 122 114 123 115 static int hwdep_release(struct snd_hwdep *hwdep, struct file *file) 124 116 { 125 117 struct snd_dice *dice = hwdep->private_data; 126 118 127 - spin_lock_irq(&dice->lock); 119 + guard(spinlock_irq)(&dice->lock); 128 120 if (dice->dev_lock_count == -1) 129 121 dice->dev_lock_count = 0; 130 - spin_unlock_irq(&dice->lock); 131 122 132 123 return 0; 133 124 }
+2 -8
sound/firewire/dice/dice-midi.c
··· 47 47 static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up) 48 48 { 49 49 struct snd_dice *dice = substrm->rmidi->private_data; 50 - unsigned long flags; 51 50 52 - spin_lock_irqsave(&dice->lock, flags); 51 + guard(spinlock_irqsave)(&dice->lock); 53 52 54 53 if (up) 55 54 amdtp_am824_midi_trigger(&dice->tx_stream[0], ··· 56 57 else 57 58 amdtp_am824_midi_trigger(&dice->tx_stream[0], 58 59 substrm->number, NULL); 59 - 60 - spin_unlock_irqrestore(&dice->lock, flags); 61 60 } 62 61 63 62 static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up) 64 63 { 65 64 struct snd_dice *dice = substrm->rmidi->private_data; 66 - unsigned long flags; 67 65 68 - spin_lock_irqsave(&dice->lock, flags); 66 + guard(spinlock_irqsave)(&dice->lock); 69 67 70 68 if (up) 71 69 amdtp_am824_midi_trigger(&dice->rx_stream[0], ··· 70 74 else 71 75 amdtp_am824_midi_trigger(&dice->rx_stream[0], 72 76 substrm->number, NULL); 73 - 74 - spin_unlock_irqrestore(&dice->lock, flags); 75 77 } 76 78 77 79 static void set_midi_substream_names(struct snd_dice *dice,
+6 -15
sound/firewire/dice/dice-stream.c
··· 677 677 678 678 int snd_dice_stream_lock_try(struct snd_dice *dice) 679 679 { 680 - int err; 680 + guard(spinlock_irq)(&dice->lock); 681 681 682 - spin_lock_irq(&dice->lock); 683 - 684 - if (dice->dev_lock_count < 0) { 685 - err = -EBUSY; 686 - goto out; 687 - } 682 + if (dice->dev_lock_count < 0) 683 + return -EBUSY; 688 684 689 685 if (dice->dev_lock_count++ == 0) 690 686 dice_lock_changed(dice); 691 - err = 0; 692 - out: 693 - spin_unlock_irq(&dice->lock); 694 - return err; 687 + return 0; 695 688 } 696 689 697 690 void snd_dice_stream_lock_release(struct snd_dice *dice) 698 691 { 699 - spin_lock_irq(&dice->lock); 692 + guard(spinlock_irq)(&dice->lock); 700 693 701 694 if (WARN_ON(dice->dev_lock_count <= 0)) 702 - goto out; 695 + return; 703 696 704 697 if (--dice->dev_lock_count == 0) 705 698 dice_lock_changed(dice); 706 - out: 707 - spin_unlock_irq(&dice->lock); 708 699 }
+3 -4
sound/firewire/dice/dice-transaction.c
··· 136 136 { 137 137 struct snd_dice *dice = callback_data; 138 138 u32 bits; 139 - unsigned long flags; 140 139 141 140 if (tcode != TCODE_WRITE_QUADLET_REQUEST) { 142 141 fw_send_response(card, request, RCODE_TYPE_ERROR); ··· 148 149 149 150 bits = be32_to_cpup(data); 150 151 151 - spin_lock_irqsave(&dice->lock, flags); 152 - dice->notification_bits |= bits; 153 - spin_unlock_irqrestore(&dice->lock, flags); 152 + scoped_guard(spinlock_irqsave, &dice->lock) { 153 + dice->notification_bits |= bits; 154 + } 154 155 155 156 fw_send_response(card, request, RCODE_COMPLETE); 156 157