Commit 6768bd10 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: seq: memory: Use guard() for locking

We can simplify the code gracefully with new guard() macro and co for
automatic cleanup of locks.

Only the code refactoring, and no functional changes.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20240227085306.9764-14-tiwai@suse.de
parent 68f014a5
...@@ -232,7 +232,6 @@ static inline void free_cell(struct snd_seq_pool *pool, ...@@ -232,7 +232,6 @@ static inline void free_cell(struct snd_seq_pool *pool,
void snd_seq_cell_free(struct snd_seq_event_cell * cell) void snd_seq_cell_free(struct snd_seq_event_cell * cell)
{ {
unsigned long flags;
struct snd_seq_pool *pool; struct snd_seq_pool *pool;
if (snd_BUG_ON(!cell)) if (snd_BUG_ON(!cell))
...@@ -241,7 +240,7 @@ void snd_seq_cell_free(struct snd_seq_event_cell * cell) ...@@ -241,7 +240,7 @@ void snd_seq_cell_free(struct snd_seq_event_cell * cell)
if (snd_BUG_ON(!pool)) if (snd_BUG_ON(!pool))
return; return;
spin_lock_irqsave(&pool->lock, flags); guard(spinlock_irqsave)(&pool->lock);
free_cell(pool, cell); free_cell(pool, cell);
if (snd_seq_ev_is_variable(&cell->event)) { if (snd_seq_ev_is_variable(&cell->event)) {
if (cell->event.data.ext.len & SNDRV_SEQ_EXT_CHAINED) { if (cell->event.data.ext.len & SNDRV_SEQ_EXT_CHAINED) {
...@@ -259,7 +258,6 @@ void snd_seq_cell_free(struct snd_seq_event_cell * cell) ...@@ -259,7 +258,6 @@ void snd_seq_cell_free(struct snd_seq_event_cell * cell)
if (snd_seq_output_ok(pool)) if (snd_seq_output_ok(pool))
wake_up(&pool->output_sleep); wake_up(&pool->output_sleep);
} }
spin_unlock_irqrestore(&pool->lock, flags);
} }
...@@ -449,9 +447,8 @@ int snd_seq_pool_init(struct snd_seq_pool *pool) ...@@ -449,9 +447,8 @@ int snd_seq_pool_init(struct snd_seq_pool *pool)
return -ENOMEM; return -ENOMEM;
/* add new cells to the free cell list */ /* add new cells to the free cell list */
spin_lock_irq(&pool->lock); guard(spinlock_irq)(&pool->lock);
if (pool->ptr) { if (pool->ptr) {
spin_unlock_irq(&pool->lock);
kvfree(cellptr); kvfree(cellptr);
return 0; return 0;
} }
...@@ -470,20 +467,16 @@ int snd_seq_pool_init(struct snd_seq_pool *pool) ...@@ -470,20 +467,16 @@ int snd_seq_pool_init(struct snd_seq_pool *pool)
/* init statistics */ /* init statistics */
pool->max_used = 0; pool->max_used = 0;
pool->total_elements = pool->size; pool->total_elements = pool->size;
spin_unlock_irq(&pool->lock);
return 0; return 0;
} }
/* refuse the further insertion to the pool */ /* refuse the further insertion to the pool */
void snd_seq_pool_mark_closing(struct snd_seq_pool *pool) void snd_seq_pool_mark_closing(struct snd_seq_pool *pool)
{ {
unsigned long flags;
if (snd_BUG_ON(!pool)) if (snd_BUG_ON(!pool))
return; return;
spin_lock_irqsave(&pool->lock, flags); guard(spinlock_irqsave)(&pool->lock);
pool->closing = 1; pool->closing = 1;
spin_unlock_irqrestore(&pool->lock, flags);
} }
/* remove events */ /* remove events */
...@@ -502,18 +495,17 @@ int snd_seq_pool_done(struct snd_seq_pool *pool) ...@@ -502,18 +495,17 @@ int snd_seq_pool_done(struct snd_seq_pool *pool)
schedule_timeout_uninterruptible(1); schedule_timeout_uninterruptible(1);
/* release all resources */ /* release all resources */
spin_lock_irq(&pool->lock); scoped_guard(spinlock_irq, &pool->lock) {
ptr = pool->ptr; ptr = pool->ptr;
pool->ptr = NULL; pool->ptr = NULL;
pool->free = NULL; pool->free = NULL;
pool->total_elements = 0; pool->total_elements = 0;
spin_unlock_irq(&pool->lock); }
kvfree(ptr); kvfree(ptr);
spin_lock_irq(&pool->lock); guard(spinlock_irq)(&pool->lock);
pool->closing = 0; pool->closing = 0;
spin_unlock_irq(&pool->lock);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment