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

ALSA: firewire: fireface: 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-15-tiwai@suse.de

+19 -53
+10 -27
sound/firewire/fireface/ff-hwdep.c
··· 72 72 poll_table *wait) 73 73 { 74 74 struct snd_ff *ff = hwdep->private_data; 75 - __poll_t events; 76 75 77 76 poll_wait(file, &ff->hwdep_wait, wait); 78 77 79 - spin_lock_irq(&ff->lock); 78 + guard(spinlock_irq)(&ff->lock); 80 79 if (ff->dev_lock_changed || has_msg(ff)) 81 - events = EPOLLIN | EPOLLRDNORM; 80 + return EPOLLIN | EPOLLRDNORM; 82 81 else 83 - events = 0; 84 - spin_unlock_irq(&ff->lock); 85 - 86 - return events; 82 + return 0; 87 83 } 88 84 89 85 static int hwdep_get_info(struct snd_ff *ff, void __user *arg) ··· 103 107 104 108 static int hwdep_lock(struct snd_ff *ff) 105 109 { 106 - int err; 107 - 108 - spin_lock_irq(&ff->lock); 110 + guard(spinlock_irq)(&ff->lock); 109 111 110 112 if (ff->dev_lock_count == 0) { 111 113 ff->dev_lock_count = -1; 112 - err = 0; 114 + return 0; 113 115 } else { 114 - err = -EBUSY; 116 + return -EBUSY; 115 117 } 116 - 117 - spin_unlock_irq(&ff->lock); 118 - 119 - return err; 120 118 } 121 119 122 120 static int hwdep_unlock(struct snd_ff *ff) 123 121 { 124 - int err; 125 - 126 - spin_lock_irq(&ff->lock); 122 + guard(spinlock_irq)(&ff->lock); 127 123 128 124 if (ff->dev_lock_count == -1) { 129 125 ff->dev_lock_count = 0; 130 - err = 0; 126 + return 0; 131 127 } else { 132 - err = -EBADFD; 128 + return -EBADFD; 133 129 } 134 - 135 - spin_unlock_irq(&ff->lock); 136 - 137 - return err; 138 130 } 139 131 140 132 static int hwdep_release(struct snd_hwdep *hwdep, struct file *file) 141 133 { 142 134 struct snd_ff *ff = hwdep->private_data; 143 135 144 - spin_lock_irq(&ff->lock); 136 + guard(spinlock_irq)(&ff->lock); 145 137 if (ff->dev_lock_count == -1) 146 138 ff->dev_lock_count = 0; 147 - spin_unlock_irq(&ff->lock); 148 139 149 140 return 0; 150 141 }
+2 -8
sound/firewire/fireface/ff-midi.c
··· 46 46 int up) 47 47 { 48 48 struct snd_ff *ff = substream->rmidi->private_data; 49 - unsigned long flags; 50 49 51 - spin_lock_irqsave(&ff->lock, flags); 50 + guard(spinlock_irqsave)(&ff->lock); 52 51 53 52 if (up) 54 53 WRITE_ONCE(ff->tx_midi_substreams[substream->number], 55 54 substream); 56 55 else 57 56 WRITE_ONCE(ff->tx_midi_substreams[substream->number], NULL); 58 - 59 - spin_unlock_irqrestore(&ff->lock, flags); 60 57 } 61 58 62 59 static void midi_playback_trigger(struct snd_rawmidi_substream *substream, 63 60 int up) 64 61 { 65 62 struct snd_ff *ff = substream->rmidi->private_data; 66 - unsigned long flags; 67 63 68 - spin_lock_irqsave(&ff->lock, flags); 64 + guard(spinlock_irqsave)(&ff->lock); 69 65 70 66 if (up || !ff->rx_midi_error[substream->number]) 71 67 schedule_work(&ff->rx_midi_work[substream->number]); 72 - 73 - spin_unlock_irqrestore(&ff->lock, flags); 74 68 } 75 69 76 70 static void set_midi_substream_names(struct snd_rawmidi_str *stream,
+6 -15
sound/firewire/fireface/ff-stream.c
··· 253 253 254 254 int snd_ff_stream_lock_try(struct snd_ff *ff) 255 255 { 256 - int err; 257 - 258 - spin_lock_irq(&ff->lock); 256 + guard(spinlock_irq)(&ff->lock); 259 257 260 258 /* user land lock this */ 261 - if (ff->dev_lock_count < 0) { 262 - err = -EBUSY; 263 - goto end; 264 - } 259 + if (ff->dev_lock_count < 0) 260 + return -EBUSY; 265 261 266 262 /* this is the first time */ 267 263 if (ff->dev_lock_count++ == 0) 268 264 snd_ff_stream_lock_changed(ff); 269 - err = 0; 270 - end: 271 - spin_unlock_irq(&ff->lock); 272 - return err; 265 + return 0; 273 266 } 274 267 275 268 void snd_ff_stream_lock_release(struct snd_ff *ff) 276 269 { 277 - spin_lock_irq(&ff->lock); 270 + guard(spinlock_irq)(&ff->lock); 278 271 279 272 if (WARN_ON(ff->dev_lock_count <= 0)) 280 - goto end; 273 + return; 281 274 if (--ff->dev_lock_count == 0) 282 275 snd_ff_stream_lock_changed(ff); 283 - end: 284 - spin_unlock_irq(&ff->lock); 285 276 }
+1 -3
sound/firewire/fireface/ff-transaction.c
··· 132 132 struct snd_ff *ff = callback_data; 133 133 __le32 *buf = data; 134 134 u32 tstamp = fw_request_get_timestamp(request); 135 - unsigned long flag; 136 135 137 136 fw_send_response(card, request, RCODE_COMPLETE); 138 137 139 138 offset -= ff->async_handler.offset; 140 139 141 - spin_lock_irqsave(&ff->lock, flag); 140 + guard(spinlock_irqsave)(&ff->lock); 142 141 ff->spec->protocol->handle_msg(ff, (unsigned int)offset, buf, length, tstamp); 143 - spin_unlock_irqrestore(&ff->lock, flag); 144 142 } 145 143 146 144 static int allocate_own_address(struct snd_ff *ff, int i)