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

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

+42 -85
+8 -8
sound/firewire/fireworks/fireworks_command.c
··· 119 119 return -ENOMEM; 120 120 121 121 /* to keep consistency of sequence number */ 122 - spin_lock(&efw->lock); 123 - if ((efw->seqnum < KERNEL_SEQNUM_MIN) || 124 - (efw->seqnum >= KERNEL_SEQNUM_MAX - 2)) 125 - efw->seqnum = KERNEL_SEQNUM_MIN; 126 - else 127 - efw->seqnum += 2; 128 - seqnum = efw->seqnum; 129 - spin_unlock(&efw->lock); 122 + scoped_guard(spinlock, &efw->lock) { 123 + if ((efw->seqnum < KERNEL_SEQNUM_MIN) || 124 + (efw->seqnum >= KERNEL_SEQNUM_MAX - 2)) 125 + efw->seqnum = KERNEL_SEQNUM_MIN; 126 + else 127 + efw->seqnum += 2; 128 + seqnum = efw->seqnum; 129 + } 130 130 131 131 /* fill transaction header fields */ 132 132 cmd_bytes = sizeof(struct snd_efw_transaction) + param_bytes;
+12 -29
sound/firewire/fireworks/fireworks_hwdep.c
··· 103 103 .lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS, 104 104 }; 105 105 106 - spin_lock_irq(&efw->lock); 107 - 108 - event.lock_status.status = (efw->dev_lock_count > 0); 109 - efw->dev_lock_changed = false; 110 - 111 - spin_unlock_irq(&efw->lock); 106 + scoped_guard(spinlock_irq, &efw->lock) { 107 + event.lock_status.status = (efw->dev_lock_count > 0); 108 + efw->dev_lock_changed = false; 109 + } 112 110 113 111 count = min_t(long, count, sizeof(event.lock_status)); 114 112 ··· 190 192 191 193 poll_wait(file, &efw->hwdep_wait, wait); 192 194 193 - spin_lock_irq(&efw->lock); 195 + guard(spinlock_irq)(&efw->lock); 194 196 if (efw->dev_lock_changed || efw->pull_ptr != efw->push_ptr) 195 197 events = EPOLLIN | EPOLLRDNORM; 196 198 else 197 199 events = 0; 198 - spin_unlock_irq(&efw->lock); 199 - 200 200 return events | EPOLLOUT; 201 201 } 202 202 ··· 221 225 static int 222 226 hwdep_lock(struct snd_efw *efw) 223 227 { 224 - int err; 225 - 226 - spin_lock_irq(&efw->lock); 228 + guard(spinlock_irq)(&efw->lock); 227 229 228 230 if (efw->dev_lock_count == 0) { 229 231 efw->dev_lock_count = -1; 230 - err = 0; 232 + return 0; 231 233 } else { 232 - err = -EBUSY; 234 + return -EBUSY; 233 235 } 234 - 235 - spin_unlock_irq(&efw->lock); 236 - 237 - return err; 238 236 } 239 237 240 238 static int 241 239 hwdep_unlock(struct snd_efw *efw) 242 240 { 243 - int err; 244 - 245 - spin_lock_irq(&efw->lock); 241 + guard(spinlock_irq)(&efw->lock); 246 242 247 243 if (efw->dev_lock_count == -1) { 248 244 efw->dev_lock_count = 0; 249 - err = 0; 245 + return 0; 250 246 } else { 251 - err = -EBADFD; 247 + return -EBADFD; 252 248 } 253 - 254 - spin_unlock_irq(&efw->lock); 255 - 256 - return err; 257 249 } 258 250 259 251 static int ··· 249 265 { 250 266 struct snd_efw *efw = hwdep->private_data; 251 267 252 - spin_lock_irq(&efw->lock); 268 + guard(spinlock_irq)(&efw->lock); 253 269 if (efw->dev_lock_count == -1) 254 270 efw->dev_lock_count = 0; 255 - spin_unlock_irq(&efw->lock); 256 271 257 272 return 0; 258 273 }
+2 -8
sound/firewire/fireworks/fireworks_midi.c
··· 46 46 static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up) 47 47 { 48 48 struct snd_efw *efw = substrm->rmidi->private_data; 49 - unsigned long flags; 50 49 51 - spin_lock_irqsave(&efw->lock, flags); 50 + guard(spinlock_irqsave)(&efw->lock); 52 51 53 52 if (up) 54 53 amdtp_am824_midi_trigger(&efw->tx_stream, ··· 55 56 else 56 57 amdtp_am824_midi_trigger(&efw->tx_stream, 57 58 substrm->number, NULL); 58 - 59 - spin_unlock_irqrestore(&efw->lock, flags); 60 59 } 61 60 62 61 static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up) 63 62 { 64 63 struct snd_efw *efw = substrm->rmidi->private_data; 65 - unsigned long flags; 66 64 67 - spin_lock_irqsave(&efw->lock, flags); 65 + guard(spinlock_irqsave)(&efw->lock); 68 66 69 67 if (up) 70 68 amdtp_am824_midi_trigger(&efw->rx_stream, ··· 69 73 else 70 74 amdtp_am824_midi_trigger(&efw->rx_stream, 71 75 substrm->number, NULL); 72 - 73 - spin_unlock_irqrestore(&efw->lock, flags); 74 76 } 75 77 76 78 static void set_midi_substream_names(struct snd_efw *efw,
+6 -15
sound/firewire/fireworks/fireworks_stream.c
··· 345 345 346 346 int snd_efw_stream_lock_try(struct snd_efw *efw) 347 347 { 348 - int err; 349 - 350 - spin_lock_irq(&efw->lock); 348 + guard(spinlock_irq)(&efw->lock); 351 349 352 350 /* user land lock this */ 353 - if (efw->dev_lock_count < 0) { 354 - err = -EBUSY; 355 - goto end; 356 - } 351 + if (efw->dev_lock_count < 0) 352 + return -EBUSY; 357 353 358 354 /* this is the first time */ 359 355 if (efw->dev_lock_count++ == 0) 360 356 snd_efw_stream_lock_changed(efw); 361 - err = 0; 362 - end: 363 - spin_unlock_irq(&efw->lock); 364 - return err; 357 + return 0; 365 358 } 366 359 367 360 void snd_efw_stream_lock_release(struct snd_efw *efw) 368 361 { 369 - spin_lock_irq(&efw->lock); 362 + guard(spinlock_irq)(&efw->lock); 370 363 371 364 if (WARN_ON(efw->dev_lock_count <= 0)) 372 - goto end; 365 + return; 373 366 if (--efw->dev_lock_count == 0) 374 367 snd_efw_stream_lock_changed(efw); 375 - end: 376 - spin_unlock_irq(&efw->lock); 377 368 }
+14 -25
sound/firewire/fireworks/fireworks_transaction.c
··· 82 82 t.state = STATE_PENDING; 83 83 init_waitqueue_head(&t.wait); 84 84 85 - spin_lock_irq(&transaction_queues_lock); 86 - list_add_tail(&t.list, &transaction_queues); 87 - spin_unlock_irq(&transaction_queues_lock); 85 + scoped_guard(spinlock_irq, &transaction_queues_lock) { 86 + list_add_tail(&t.list, &transaction_queues); 87 + } 88 88 89 89 tries = 0; 90 90 do { ··· 107 107 } 108 108 } while (1); 109 109 110 - spin_lock_irq(&transaction_queues_lock); 111 - list_del(&t.list); 112 - spin_unlock_irq(&transaction_queues_lock); 110 + scoped_guard(spinlock_irq, &transaction_queues_lock) { 111 + list_del(&t.list); 112 + } 113 113 114 114 return ret; 115 115 } ··· 123 123 t = (struct snd_efw_transaction *)data; 124 124 length = min_t(size_t, be32_to_cpu(t->length) * sizeof(u32), length); 125 125 126 - spin_lock(&efw->lock); 126 + guard(spinlock)(&efw->lock); 127 127 128 128 if (efw->push_ptr < efw->pull_ptr) 129 129 capacity = (unsigned int)(efw->pull_ptr - efw->push_ptr); ··· 134 134 /* confirm enough space for this response */ 135 135 if (capacity < length) { 136 136 *rcode = RCODE_CONFLICT_ERROR; 137 - goto end; 137 + return; 138 138 } 139 139 140 140 /* copy to ring buffer */ ··· 157 157 wake_up(&efw->hwdep_wait); 158 158 159 159 *rcode = RCODE_COMPLETE; 160 - end: 161 - spin_unlock_irq(&efw->lock); 162 160 } 163 161 164 162 static void ··· 167 169 struct snd_efw *efw; 168 170 unsigned int i; 169 171 170 - spin_lock_irq(&instances_lock); 172 + guard(spinlock_irq)(&instances_lock); 171 173 172 174 for (i = 0; i < SNDRV_CARDS; i++) { 173 175 efw = instances[i]; ··· 184 186 break; 185 187 } 186 188 if (i == SNDRV_CARDS) 187 - goto end; 189 + return; 188 190 189 191 copy_resp_to_buf(efw, data, length, rcode); 190 - end: 191 - spin_unlock(&instances_lock); 192 192 } 193 193 194 194 static void ··· 195 199 { 196 200 struct fw_device *device; 197 201 struct transaction_queue *t; 198 - unsigned long flags; 199 202 200 - spin_lock_irqsave(&transaction_queues_lock, flags); 203 + guard(spinlock_irqsave)(&transaction_queues_lock); 201 204 list_for_each_entry(t, &transaction_queues, list) { 202 205 device = fw_parent_device(t->unit); 203 206 if ((device->card != card) || ··· 214 219 *rcode = RCODE_COMPLETE; 215 220 } 216 221 } 217 - spin_unlock_irqrestore(&transaction_queues_lock, flags); 218 222 } 219 223 220 224 static void ··· 253 259 { 254 260 unsigned int i; 255 261 256 - spin_lock_irq(&instances_lock); 262 + guard(spinlock_irq)(&instances_lock); 257 263 258 264 for (i = 0; i < SNDRV_CARDS; i++) { 259 265 if (instances[i] != NULL) ··· 261 267 instances[i] = efw; 262 268 break; 263 269 } 264 - 265 - spin_unlock_irq(&instances_lock); 266 270 } 267 271 268 272 void snd_efw_transaction_remove_instance(struct snd_efw *efw) 269 273 { 270 274 unsigned int i; 271 275 272 - spin_lock_irq(&instances_lock); 276 + guard(spinlock_irq)(&instances_lock); 273 277 274 278 for (i = 0; i < SNDRV_CARDS; i++) { 275 279 if (instances[i] != efw) 276 280 continue; 277 281 instances[i] = NULL; 278 282 } 279 - 280 - spin_unlock_irq(&instances_lock); 281 283 } 282 284 283 285 void snd_efw_transaction_bus_reset(struct fw_unit *unit) 284 286 { 285 287 struct transaction_queue *t; 286 288 287 - spin_lock_irq(&transaction_queues_lock); 289 + guard(spinlock_irq)(&transaction_queues_lock); 288 290 list_for_each_entry(t, &transaction_queues, list) { 289 291 if ((t->unit == unit) && 290 292 (t->state == STATE_PENDING)) { ··· 288 298 wake_up(&t->wait); 289 299 } 290 300 } 291 - spin_unlock_irq(&transaction_queues_lock); 292 301 } 293 302 294 303 static struct fw_address_handler resp_register_handler = {