]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: ctxfi: Use guard() for mutex locks
authorTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 14:42:57 +0000 (16:42 +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-23-tiwai@suse.de
sound/pci/ctxfi/ctatc.c
sound/pci/ctxfi/ctvmem.c

index 2a3e9d8ba7dbe71aa5222d9242e0702f0e7aa398..14779b383d9ea377c50b270334b2067c0306881b 100644 (file)
@@ -295,10 +295,10 @@ static int atc_pcm_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm)
        src = apcm->src;
        for (i = 0; i < n_amixer; i++) {
                amixer = apcm->amixers[i];
-               mutex_lock(&atc->atc_mutex);
-               amixer->ops->setup(amixer, &src->rsc,
-                                       INIT_VOL, atc->pcm[i+device*2]);
-               mutex_unlock(&atc->atc_mutex);
+               scoped_guard(mutex, &atc->atc_mutex) {
+                       amixer->ops->setup(amixer, &src->rsc,
+                                          INIT_VOL, atc->pcm[i+device*2]);
+               }
                src = src->ops->next_interleave(src);
                if (!src)
                        src = apcm->src;
@@ -874,7 +874,7 @@ spdif_passthru_playback_setup(struct ct_atc *atc, struct ct_atc_pcm *apcm)
                return -ENOENT;
        }
 
-       mutex_lock(&atc->atc_mutex);
+       guard(mutex)(&atc->atc_mutex);
        dao->ops->get_spos(dao, &status);
        if (((status >> 24) & IEC958_AES3_CON_FS) != iec958_con_fs) {
                status &= ~(IEC958_AES3_CON_FS << 24);
@@ -884,7 +884,6 @@ spdif_passthru_playback_setup(struct ct_atc *atc, struct ct_atc_pcm *apcm)
        }
        if ((rate != atc->pll_rate) && (32000 != rate))
                err = atc_pll_init(atc, rate);
-       mutex_unlock(&atc->atc_mutex);
 
        return err;
 }
@@ -921,13 +920,13 @@ spdif_passthru_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm)
                        src = apcm->src;
        }
        /* Connect to SPDIFOO */
-       mutex_lock(&atc->atc_mutex);
-       dao = container_of(atc->daios[SPDIFOO], struct dao, daio);
-       amixer = apcm->amixers[0];
-       dao->ops->set_left_input(dao, &amixer->rsc);
-       amixer = apcm->amixers[1];
-       dao->ops->set_right_input(dao, &amixer->rsc);
-       mutex_unlock(&atc->atc_mutex);
+       scoped_guard(mutex, &atc->atc_mutex) {
+               dao = container_of(atc->daios[SPDIFOO], struct dao, daio);
+               amixer = apcm->amixers[0];
+               dao->ops->set_left_input(dao, &amixer->rsc);
+               amixer = apcm->amixers[1];
+               dao->ops->set_right_input(dao, &amixer->rsc);
+       }
 
        ct_timer_prepare(apcm->timer);
 
@@ -1115,7 +1114,7 @@ static int atc_spdif_out_passthru(struct ct_atc *atc, unsigned char state)
        struct rsc *rscs[2] = {NULL};
        unsigned int spos = 0;
 
-       mutex_lock(&atc->atc_mutex);
+       guard(mutex)(&atc->atc_mutex);
        dao = container_of(atc->daios[SPDIFOO], struct dao, daio);
        da_dsc.msr = state ? 1 : atc->msr;
        da_dsc.passthru = state ? 1 : 0;
@@ -1133,7 +1132,6 @@ static int atc_spdif_out_passthru(struct ct_atc *atc, unsigned char state)
        }
        dao->ops->set_spos(dao, spos);
        dao->ops->commit_write(dao);
-       mutex_unlock(&atc->atc_mutex);
 
        return err;
 }
index 7a805c4a58e1433c6975904007905868bc289a2e..823d6e240a07c047373ab2c20f0ac2c0ed975ed9 100644 (file)
@@ -29,7 +29,7 @@
 static struct ct_vm_block *
 get_vm_block(struct ct_vm *vm, unsigned int size, struct ct_atc *atc)
 {
-       struct ct_vm_block *block = NULL, *entry;
+       struct ct_vm_block *block, *entry;
        struct list_head *pos;
 
        size = CT_PAGE_ALIGN(size);
@@ -39,26 +39,25 @@ get_vm_block(struct ct_vm *vm, unsigned int size, struct ct_atc *atc)
                return NULL;
        }
 
-       mutex_lock(&vm->lock);
+       guard(mutex)(&vm->lock);
        list_for_each(pos, &vm->unused) {
                entry = list_entry(pos, struct ct_vm_block, list);
                if (entry->size >= size)
                        break; /* found a block that is big enough */
        }
        if (pos == &vm->unused)
-               goto out;
+               return NULL;
 
        if (entry->size == size) {
                /* Move the vm node from unused list to used list directly */
                list_move(&entry->list, &vm->used);
                vm->size -= size;
-               block = entry;
-               goto out;
+               return entry;
        }
 
        block = kzalloc(sizeof(*block), GFP_KERNEL);
        if (!block)
-               goto out;
+               return NULL;
 
        block->addr = entry->addr;
        block->size = size;
@@ -67,8 +66,6 @@ get_vm_block(struct ct_vm *vm, unsigned int size, struct ct_atc *atc)
        entry->size -= size;
        vm->size -= size;
 
- out:
-       mutex_unlock(&vm->lock);
        return block;
 }
 
@@ -79,7 +76,7 @@ static void put_vm_block(struct ct_vm *vm, struct ct_vm_block *block)
 
        block->size = CT_PAGE_ALIGN(block->size);
 
-       mutex_lock(&vm->lock);
+       guard(mutex)(&vm->lock);
        list_del(&block->list);
        vm->size += block->size;
 
@@ -116,7 +113,6 @@ static void put_vm_block(struct ct_vm *vm, struct ct_vm_block *block)
                pos = pre;
                pre = pos->prev;
        }
-       mutex_unlock(&vm->lock);
 }
 
 /* Map host addr (kmalloced/vmalloced) to device logical addr. */