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

ALSA: seq: Clean up fifo locking with guard

Yet more cleanup, now for seq_fifo.c about its refcount calls; the
manual refcount calls (either snd_use_lock_*() or snd_seq_fifo_lock())
are replaced with guard(snd_seq_fifo).

Only code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250827080520.7544-8-tiwai@suse.de

+6 -13
+1 -2
sound/core/seq/seq_clientmgr.c
··· 416 416 417 417 cell = NULL; 418 418 err = 0; 419 - snd_seq_fifo_lock(fifo); 419 + guard(snd_seq_fifo)(fifo); 420 420 421 421 if (IS_ENABLED(CONFIG_SND_SEQ_UMP) && client->midi_version > 0) 422 422 aligned_size = sizeof(struct snd_seq_ump_event); ··· 474 474 if (err == -EAGAIN && result > 0) 475 475 err = 0; 476 476 } 477 - snd_seq_fifo_unlock(fifo); 478 477 479 478 return (err < 0) ? err : result; 480 479 }
+4 -11
sound/core/seq/seq_fifo.c
··· 106 106 if (snd_BUG_ON(!f)) 107 107 return -EINVAL; 108 108 109 - snd_use_lock_use(&f->use_lock); 109 + guard(snd_seq_fifo)(f); 110 110 err = snd_seq_event_dup(f->pool, event, &cell, 1, NULL, NULL); /* always non-blocking */ 111 111 if (err < 0) { 112 112 if ((err == -ENOMEM) || (err == -EAGAIN)) 113 113 atomic_inc(&f->overflow); 114 - snd_use_lock_free(&f->use_lock); 115 114 return err; 116 115 } 117 116 ··· 128 129 /* wakeup client */ 129 130 if (waitqueue_active(&f->input_sleep)) 130 131 wake_up(&f->input_sleep); 131 - 132 - snd_use_lock_free(&f->use_lock); 133 132 134 133 return 0; /* success */ 135 134 ··· 260 263 /* get the number of unused cells safely */ 261 264 int snd_seq_fifo_unused_cells(struct snd_seq_fifo *f) 262 265 { 263 - int cells; 264 - 265 266 if (!f) 266 267 return 0; 267 268 268 - snd_use_lock_use(&f->use_lock); 269 - scoped_guard(spinlock_irqsave, &f->lock) 270 - cells = snd_seq_unused_cells(f->pool); 271 - snd_use_lock_free(&f->use_lock); 272 - return cells; 269 + guard(snd_seq_fifo)(f); 270 + guard(spinlock_irqsave)(&f->lock); 271 + return snd_seq_unused_cells(f->pool); 273 272 }
+1
sound/core/seq/seq_fifo.h
··· 37 37 /* lock fifo from release */ 38 38 #define snd_seq_fifo_lock(fifo) snd_use_lock_use(&(fifo)->use_lock) 39 39 #define snd_seq_fifo_unlock(fifo) snd_use_lock_free(&(fifo)->use_lock) 40 + DEFINE_GUARD(snd_seq_fifo, struct snd_seq_fifo *, snd_seq_fifo_lock(_T), snd_seq_fifo_unlock(_T)) 40 41 41 42 /* get a cell from fifo - fifo should be locked */ 42 43 int snd_seq_fifo_cell_out(struct snd_seq_fifo *f, struct snd_seq_event_cell **cellp, int nonblock);