]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: seq: Clean up fifo locking with guard
authorTakashi Iwai <tiwai@suse.de>
Wed, 27 Aug 2025 08:05:13 +0000 (10:05 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 09:52:36 +0000 (11:52 +0200)
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
sound/core/seq/seq_clientmgr.c
sound/core/seq/seq_fifo.c
sound/core/seq/seq_fifo.h

index 38ad5bbd270695f70002d64820a95a810ab1c483..f9a6e497f997ccb8e730b7801ab9f801cab1e1bf 100644 (file)
@@ -416,7 +416,7 @@ static ssize_t snd_seq_read(struct file *file, char __user *buf, size_t count,
 
        cell = NULL;
        err = 0;
-       snd_seq_fifo_lock(fifo);
+       guard(snd_seq_fifo)(fifo);
 
        if (IS_ENABLED(CONFIG_SND_SEQ_UMP) && client->midi_version > 0)
                aligned_size = sizeof(struct snd_seq_ump_event);
@@ -474,7 +474,6 @@ static ssize_t snd_seq_read(struct file *file, char __user *buf, size_t count,
                if (err == -EAGAIN && result > 0)
                        err = 0;
        }
-       snd_seq_fifo_unlock(fifo);
 
        return (err < 0) ? err : result;
 }
index 3a10b081f129c30d677a9e834a7477a065fd8044..f23c6b7ae2403ccfd18acedd305624c780394df6 100644 (file)
@@ -106,12 +106,11 @@ int snd_seq_fifo_event_in(struct snd_seq_fifo *f,
        if (snd_BUG_ON(!f))
                return -EINVAL;
 
-       snd_use_lock_use(&f->use_lock);
+       guard(snd_seq_fifo)(f);
        err = snd_seq_event_dup(f->pool, event, &cell, 1, NULL, NULL); /* always non-blocking */
        if (err < 0) {
                if ((err == -ENOMEM) || (err == -EAGAIN))
                        atomic_inc(&f->overflow);
-               snd_use_lock_free(&f->use_lock);
                return err;
        }
                
@@ -130,8 +129,6 @@ int snd_seq_fifo_event_in(struct snd_seq_fifo *f,
        if (waitqueue_active(&f->input_sleep))
                wake_up(&f->input_sleep);
 
-       snd_use_lock_free(&f->use_lock);
-
        return 0; /* success */
 
 }
@@ -263,14 +260,10 @@ int snd_seq_fifo_resize(struct snd_seq_fifo *f, int poolsize)
 /* get the number of unused cells safely */
 int snd_seq_fifo_unused_cells(struct snd_seq_fifo *f)
 {
-       int cells;
-
        if (!f)
                return 0;
 
-       snd_use_lock_use(&f->use_lock);
-       scoped_guard(spinlock_irqsave, &f->lock)
-               cells = snd_seq_unused_cells(f->pool);
-       snd_use_lock_free(&f->use_lock);
-       return cells;
+       guard(snd_seq_fifo)(f);
+       guard(spinlock_irqsave)(&f->lock);
+       return snd_seq_unused_cells(f->pool);
 }
index b56a7b897c9c313f9b91be1069c1a84da2866132..4c9c49127746b90c12fac10a9971b56ed87ef741 100644 (file)
@@ -37,6 +37,7 @@ int snd_seq_fifo_event_in(struct snd_seq_fifo *f, struct snd_seq_event *event);
 /* lock fifo from release */
 #define snd_seq_fifo_lock(fifo)                snd_use_lock_use(&(fifo)->use_lock)
 #define snd_seq_fifo_unlock(fifo)      snd_use_lock_free(&(fifo)->use_lock)
+DEFINE_GUARD(snd_seq_fifo, struct snd_seq_fifo *, snd_seq_fifo_lock(_T), snd_seq_fifo_unlock(_T))
 
 /* get a cell from fifo - fifo should be locked */
 int snd_seq_fifo_cell_out(struct snd_seq_fifo *f, struct snd_seq_event_cell **cellp, int nonblock);