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

Only code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250829144342.4290-27-tiwai@suse.de
sound/pci/emu10k1/emufx.c
sound/pci/emu10k1/memory.c

index 7db0660e6b61f4ee2a4c113f5d594ede403aa956..aaf488978b18120363f1119e8b1f4e6da3e486a7 100644 (file)
@@ -1026,12 +1026,12 @@ static int snd_emu10k1_icode_poke(struct snd_emu10k1 *emu,
                                  struct snd_emu10k1_fx8010_code *icode,
                                  bool in_kernel)
 {
-       int err = 0;
+       int err;
 
-       mutex_lock(&emu->fx8010.lock);
+       guard(mutex)(&emu->fx8010.lock);
        err = snd_emu10k1_verify_controls(emu, icode, in_kernel);
        if (err < 0)
-               goto __error;
+               return err;
        strscpy(emu->fx8010.name, icode->name, sizeof(emu->fx8010.name));
        /* stop FX processor - this may be dangerous, but it's better to miss
           some samples than generate wrong ones - [jk] */
@@ -1042,27 +1042,25 @@ static int snd_emu10k1_icode_poke(struct snd_emu10k1 *emu,
        /* ok, do the main job */
        err = snd_emu10k1_del_controls(emu, icode, in_kernel);
        if (err < 0)
-               goto __error;
+               return err;
        err = snd_emu10k1_gpr_poke(emu, icode, in_kernel);
        if (err < 0)
-               goto __error;
+               return err;
        err = snd_emu10k1_tram_poke(emu, icode, in_kernel);
        if (err < 0)
-               goto __error;
+               return err;
        err = snd_emu10k1_code_poke(emu, icode, in_kernel);
        if (err < 0)
-               goto __error;
+               return err;
        err = snd_emu10k1_add_controls(emu, icode, in_kernel);
        if (err < 0)
-               goto __error;
+               return err;
        /* start FX processor when the DSP code is updated */
        if (emu->audigy)
                snd_emu10k1_ptr_write(emu, A_DBG, 0, emu->fx8010.dbg);
        else
                snd_emu10k1_ptr_write(emu, DBG, 0, emu->fx8010.dbg);
-      __error:
-       mutex_unlock(&emu->fx8010.lock);
-       return err;
+       return 0;
 }
 
 static int snd_emu10k1_icode_peek(struct snd_emu10k1 *emu,
@@ -1070,7 +1068,7 @@ static int snd_emu10k1_icode_peek(struct snd_emu10k1 *emu,
 {
        int err;
 
-       mutex_lock(&emu->fx8010.lock);
+       guard(mutex)(&emu->fx8010.lock);
        strscpy(icode->name, emu->fx8010.name, sizeof(icode->name));
        /* ok, do the main job */
        err = snd_emu10k1_gpr_peek(emu, icode);
@@ -1080,7 +1078,6 @@ static int snd_emu10k1_icode_peek(struct snd_emu10k1 *emu,
                err = snd_emu10k1_code_peek(emu, icode);
        if (err >= 0)
                err = snd_emu10k1_list_controls(emu, icode);
-       mutex_unlock(&emu->fx8010.lock);
        return err;
 }
 
@@ -1098,7 +1095,7 @@ static int snd_emu10k1_ipcm_poke(struct snd_emu10k1 *emu,
        if (ipcm->channels > 32)
                return -EINVAL;
        pcm = &emu->fx8010.pcm[ipcm->substream];
-       mutex_lock(&emu->fx8010.lock);
+       guard(mutex)(&emu->fx8010.lock);
        spin_lock_irq(&emu->reg_lock);
        if (pcm->opened) {
                err = -EBUSY;
@@ -1128,7 +1125,6 @@ static int snd_emu10k1_ipcm_poke(struct snd_emu10k1 *emu,
        }
       __error:
        spin_unlock_irq(&emu->reg_lock);
-       mutex_unlock(&emu->fx8010.lock);
        return err;
 }
 
@@ -1144,7 +1140,7 @@ static int snd_emu10k1_ipcm_peek(struct snd_emu10k1 *emu,
        ipcm->substream = array_index_nospec(ipcm->substream,
                                             EMU10K1_FX8010_PCM_COUNT);
        pcm = &emu->fx8010.pcm[ipcm->substream];
-       mutex_lock(&emu->fx8010.lock);
+       guard(mutex)(&emu->fx8010.lock);
        spin_lock_irq(&emu->reg_lock);
        ipcm->channels = pcm->channels;
        ipcm->tram_start = pcm->tram_start;
@@ -1160,7 +1156,6 @@ static int snd_emu10k1_ipcm_peek(struct snd_emu10k1 *emu,
        ipcm->res1 = ipcm->res2 = 0;
        ipcm->pad = 0;
        spin_unlock_irq(&emu->reg_lock);
-       mutex_unlock(&emu->fx8010.lock);
        return err;
 }
 
@@ -2547,9 +2542,9 @@ static int snd_emu10k1_fx8010_ioctl(struct snd_hwdep * hw, struct file *file, un
                        return -EPERM;
                if (get_user(addr, (unsigned int __user *)argp))
                        return -EFAULT;
-               mutex_lock(&emu->fx8010.lock);
-               res = snd_emu10k1_fx8010_tram_setup(emu, addr);
-               mutex_unlock(&emu->fx8010.lock);
+               scoped_guard(mutex, &emu->fx8010.lock) {
+                       res = snd_emu10k1_fx8010_tram_setup(emu, addr);
+               }
                return res;
        case SNDRV_EMU10K1_IOCTL_STOP:
                if (!capable(CAP_SYS_ADMIN))
index f6982bc6ff0d0ea603cccf939a33cf53be22c824..3bccba48f82c11d36ce846d7db3ed8da5241592f 100644 (file)
@@ -315,12 +315,10 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *subst
        if (snd_BUG_ON(!hdr))
                return NULL;
 
-       mutex_lock(&hdr->block_mutex);
+       guard(mutex)(&hdr->block_mutex);
        blk = search_empty(emu, runtime->dma_bytes);
-       if (blk == NULL) {
-               mutex_unlock(&hdr->block_mutex);
+       if (blk == NULL)
                return NULL;
-       }
        /* fill buffer addresses but pointers are not stored so that
         * snd_free_pci_page() is not called in synth_free()
         */
@@ -335,7 +333,6 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *subst
                if (! is_valid_page(emu, addr)) {
                        dev_err_ratelimited(emu->card->dev,
                                "emu: failure page = %d\n", idx);
-                       mutex_unlock(&hdr->block_mutex);
                        return NULL;
                }
                emu->page_addr_table[page] = addr;
@@ -347,10 +344,8 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *subst
        err = snd_emu10k1_memblk_map(emu, blk);
        if (err < 0) {
                __snd_util_mem_free(hdr, (struct snd_util_memblk *)blk);
-               mutex_unlock(&hdr->block_mutex);
                return NULL;
        }
-       mutex_unlock(&hdr->block_mutex);
        return (struct snd_util_memblk *)blk;
 }
 
@@ -407,19 +402,15 @@ snd_emu10k1_synth_alloc(struct snd_emu10k1 *hw, unsigned int size)
        struct snd_emu10k1_memblk *blk;
        struct snd_util_memhdr *hdr = hw->memhdr; 
 
-       mutex_lock(&hdr->block_mutex);
+       guard(mutex)(&hdr->block_mutex);
        blk = (struct snd_emu10k1_memblk *)__snd_util_mem_alloc(hdr, size);
-       if (blk == NULL) {
-               mutex_unlock(&hdr->block_mutex);
+       if (blk == NULL)
                return NULL;
-       }
        if (synth_alloc_pages(hw, blk)) {
                __snd_util_mem_free(hdr, (struct snd_util_memblk *)blk);
-               mutex_unlock(&hdr->block_mutex);
                return NULL;
        }
        snd_emu10k1_memblk_map(hw, blk);
-       mutex_unlock(&hdr->block_mutex);
        return (struct snd_util_memblk *)blk;
 }
 
@@ -435,14 +426,13 @@ snd_emu10k1_synth_free(struct snd_emu10k1 *emu, struct snd_util_memblk *memblk)
        struct snd_emu10k1_memblk *blk = (struct snd_emu10k1_memblk *)memblk;
        unsigned long flags;
 
-       mutex_lock(&hdr->block_mutex);
+       guard(mutex)(&hdr->block_mutex);
        spin_lock_irqsave(&emu->memblk_lock, flags);
        if (blk->mapped_page >= 0)
                unmap_memblk(emu, blk);
        spin_unlock_irqrestore(&emu->memblk_lock, flags);
        synth_free_pages(emu, blk);
        __snd_util_mem_free(hdr, memblk);
-       mutex_unlock(&hdr->block_mutex);
        return 0;
 }