]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: gus: Use guard() for mutex locks
authorTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 14:52:47 +0000 (16:52 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 1 Sep 2025 11:53:02 +0000 (13:53 +0200)
Replace the manual mutex lock/unlock pairs with guard() for code
simplification.

As replaced with the guard(mutex), no longer used snd_gf1_mem_lock()
is dropped, too.

Only code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250829145300.5460-8-tiwai@suse.de
include/sound/gus.h
sound/isa/gus/gus_dma.c
sound/isa/gus/gus_main.c
sound/isa/gus/gus_mem.c

index 1c8fb6c93e5014375a5591747a0177babda67ae7..321ae93625ebd90e6aa3f8f0913f4ed7f284af16 100644 (file)
@@ -515,7 +515,6 @@ struct _SND_IW_LFO_PROGRAM {
 
 /* gus_mem.c */
 
-void snd_gf1_mem_lock(struct snd_gf1_mem * alloc, int xup);
 int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * block);
 struct snd_gf1_mem_block *snd_gf1_mem_alloc(struct snd_gf1_mem * alloc, int owner,
                                       char *name, int size, int w_16,
index bb5a4e2fbfb3c1cc24673df478a5b124abe2accc..7b2e7878adc7938e7bbb2cc25739ce9be35cb776 100644 (file)
@@ -143,18 +143,15 @@ static void snd_gf1_dma_interrupt(struct snd_gus_card * gus)
 
 int snd_gf1_dma_init(struct snd_gus_card * gus)
 {
-       mutex_lock(&gus->dma_mutex);
+       guard(mutex)(&gus->dma_mutex);
        gus->gf1.dma_shared++;
-       if (gus->gf1.dma_shared > 1) {
-               mutex_unlock(&gus->dma_mutex);
+       if (gus->gf1.dma_shared > 1)
                return 0;
-       }
        gus->gf1.interrupt_handler_dma_write = snd_gf1_dma_interrupt;
        gus->gf1.dma_data_pcm = 
        gus->gf1.dma_data_pcm_last =
        gus->gf1.dma_data_synth = 
        gus->gf1.dma_data_synth_last = NULL;
-       mutex_unlock(&gus->dma_mutex);
        return 0;
 }
 
@@ -162,7 +159,7 @@ int snd_gf1_dma_done(struct snd_gus_card * gus)
 {
        struct snd_gf1_dma_block *block;
 
-       mutex_lock(&gus->dma_mutex);
+       guard(mutex)(&gus->dma_mutex);
        gus->gf1.dma_shared--;
        if (!gus->gf1.dma_shared) {
                snd_dma_disable(gus->gf1.dma1);
@@ -179,7 +176,6 @@ int snd_gf1_dma_done(struct snd_gus_card * gus)
                gus->gf1.dma_data_pcm_last =
                gus->gf1.dma_data_synth_last = NULL;
        }
-       mutex_unlock(&gus->dma_mutex);
        return 0;
 }
 
index 873ef4046cd699daf07cb486f02e7aea881f1f0c..a82185c86143e8a98dcfbf51d31d99ebe30561ed 100644 (file)
@@ -447,4 +447,3 @@ EXPORT_SYMBOL(snd_gf1_translate_freq);
 EXPORT_SYMBOL(snd_gf1_mem_alloc);
 EXPORT_SYMBOL(snd_gf1_mem_xfree);
 EXPORT_SYMBOL(snd_gf1_mem_free);
-EXPORT_SYMBOL(snd_gf1_mem_lock);
index 054058779db608d97d4fb24a567da59759e0d9c1..8d95d8d5abdfd481499a9165c3e6ce79b74e8c8b 100644 (file)
@@ -15,15 +15,6 @@ static void snd_gf1_mem_info_read(struct snd_info_entry *entry,
                                  struct snd_info_buffer *buffer);
 #endif
 
-void snd_gf1_mem_lock(struct snd_gf1_mem * alloc, int xup)
-{
-       if (!xup) {
-               mutex_lock(&alloc->memory_mutex);
-       } else {
-               mutex_unlock(&alloc->memory_mutex);
-       }
-}
-
 static struct snd_gf1_mem_block *
 snd_gf1_mem_xalloc(struct snd_gf1_mem *alloc, struct snd_gf1_mem_block *block,
                   const char *name)
@@ -50,7 +41,6 @@ snd_gf1_mem_xalloc(struct snd_gf1_mem *alloc, struct snd_gf1_mem_block *block,
                                alloc->first = nblock;
                        else
                                nblock->prev->next = nblock;
-                       mutex_unlock(&alloc->memory_mutex);
                        return nblock;
                }
                pblock = pblock->next;
@@ -71,7 +61,6 @@ int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * blo
 {
        if (block->share) {     /* ok.. shared block */
                block->share--;
-               mutex_unlock(&alloc->memory_mutex);
                return 0;
        }
        if (alloc->first == block) {
@@ -183,7 +172,7 @@ struct snd_gf1_mem_block *snd_gf1_mem_alloc(struct snd_gf1_mem * alloc, int owne
 {
        struct snd_gf1_mem_block block, *nblock;
 
-       snd_gf1_mem_lock(alloc, 0);
+       guard(mutex)(&alloc->memory_mutex);
        if (share_id != NULL) {
                nblock = snd_gf1_mem_share(alloc, share_id);
                if (nblock != NULL) {
@@ -193,36 +182,27 @@ struct snd_gf1_mem_block *snd_gf1_mem_alloc(struct snd_gf1_mem * alloc, int owne
                                goto __std;
                        }
                        nblock->share++;
-                       snd_gf1_mem_lock(alloc, 1);
                        return NULL;
                }
        }
       __std:
-       if (snd_gf1_mem_find(alloc, &block, size, w_16, align) < 0) {
-               snd_gf1_mem_lock(alloc, 1);
+       if (snd_gf1_mem_find(alloc, &block, size, w_16, align) < 0)
                return NULL;
-       }
        if (share_id != NULL)
                memcpy(&block.share_id, share_id, sizeof(block.share_id));
        block.owner = owner;
        nblock = snd_gf1_mem_xalloc(alloc, &block, name);
-       snd_gf1_mem_lock(alloc, 1);
        return nblock;
 }
 
 int snd_gf1_mem_free(struct snd_gf1_mem * alloc, unsigned int address)
 {
-       int result;
        struct snd_gf1_mem_block *block;
 
-       snd_gf1_mem_lock(alloc, 0);
+       guard(mutex)(&alloc->memory_mutex);
        block = snd_gf1_mem_look(alloc, address);
-       if (block) {
-               result = snd_gf1_mem_xfree(alloc, block);
-               snd_gf1_mem_lock(alloc, 1);
-               return result;
-       }
-       snd_gf1_mem_lock(alloc, 1);
+       if (block)
+               return snd_gf1_mem_xfree(alloc, block);
        return -EINVAL;
 }
 
@@ -282,7 +262,7 @@ static void snd_gf1_mem_info_read(struct snd_info_entry *entry,
 
        gus = entry->private_data;
        alloc = &gus->gf1.mem_alloc;
-       mutex_lock(&alloc->memory_mutex);
+       guard(mutex)(&alloc->memory_mutex);
        snd_iprintf(buffer, "8-bit banks       : \n    ");
        for (i = 0; i < 4; i++)
                snd_iprintf(buffer, "0x%06x (%04ik)%s", alloc->banks_8[i].address, alloc->banks_8[i].size >> 10, i + 1 < 4 ? "," : "");
@@ -326,7 +306,6 @@ static void snd_gf1_mem_info_read(struct snd_info_entry *entry,
        }
        snd_iprintf(buffer, "  Total: memory = %i, used = %i, free = %i\n",
                    total, used, total - used);
-       mutex_unlock(&alloc->memory_mutex);
 #if 0
        ultra_iprintf(buffer, "  Verify: free = %i, max 8-bit block = %i, max 16-bit block = %i\n",
                      ultra_memory_free_size(card, &card->gf1.mem_alloc),