summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2025-08-29 17:13:17 +0200
committerTakashi Iwai <tiwai@suse.de>2025-09-01 13:54:26 +0200
commiteff259d5b90508fe09edb172d2d4ec5487edf992 (patch)
tree983ca9c8649085920121a5f5f8ec51c06e6e68bb
parentcc8c535320913c6476fb068309f2e78c98dc8caf (diff)
ALSA: synth: Use guard() for mutex locks
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/20250829151335.7342-4-tiwai@suse.de
-rw-r--r--sound/synth/emux/emux_proc.c6
-rw-r--r--sound/synth/emux/emux_seq.c17
-rw-r--r--sound/synth/util_mem.c17
3 files changed, 12 insertions, 28 deletions
diff --git a/sound/synth/emux/emux_proc.c b/sound/synth/emux/emux_proc.c
index 820351f52551..16d6c9a1e24f 100644
--- a/sound/synth/emux/emux_proc.c
+++ b/sound/synth/emux/emux_proc.c
@@ -19,7 +19,7 @@ snd_emux_proc_info_read(struct snd_info_entry *entry,
int i;
emu = entry->private_data;
- mutex_lock(&emu->register_mutex);
+ guard(mutex)(&emu->register_mutex);
if (emu->name)
snd_iprintf(buf, "Device: %s\n", emu->name);
snd_iprintf(buf, "Ports: %d\n", emu->num_ports);
@@ -38,13 +38,12 @@ snd_emux_proc_info_read(struct snd_info_entry *entry,
snd_iprintf(buf, "Memory Size: 0\n");
}
if (emu->sflist) {
- mutex_lock(&emu->sflist->presets_mutex);
+ guard(mutex)(&emu->sflist->presets_mutex);
snd_iprintf(buf, "SoundFonts: %d\n", emu->sflist->fonts_size);
snd_iprintf(buf, "Instruments: %d\n", emu->sflist->zone_counter);
snd_iprintf(buf, "Samples: %d\n", emu->sflist->sample_counter);
snd_iprintf(buf, "Locked Instruments: %d\n", emu->sflist->zone_locked);
snd_iprintf(buf, "Locked Samples: %d\n", emu->sflist->sample_locked);
- mutex_unlock(&emu->sflist->presets_mutex);
}
#if 0 /* debug */
if (emu->voices[0].state != SNDRV_EMUX_ST_OFF && emu->voices[0].ch >= 0) {
@@ -85,7 +84,6 @@ snd_emux_proc_info_read(struct snd_info_entry *entry,
snd_iprintf(buf, "sample_mode=%x, rate=%x\n", vp->reg.sample_mode, vp->reg.rate_offset);
}
#endif
- mutex_unlock(&emu->register_mutex);
}
diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
index 9daced0e6c59..9d63ac006aa5 100644
--- a/sound/synth/emux/emux_seq.c
+++ b/sound/synth/emux/emux_seq.c
@@ -272,12 +272,8 @@ __snd_emux_inc_count(struct snd_emux *emu)
int snd_emux_inc_count(struct snd_emux *emu)
{
- int ret;
-
- mutex_lock(&emu->register_mutex);
- ret = __snd_emux_inc_count(emu);
- mutex_unlock(&emu->register_mutex);
- return ret;
+ guard(mutex)(&emu->register_mutex);
+ return __snd_emux_inc_count(emu);
}
/*
@@ -295,9 +291,8 @@ __snd_emux_dec_count(struct snd_emux *emu)
void snd_emux_dec_count(struct snd_emux *emu)
{
- mutex_lock(&emu->register_mutex);
+ guard(mutex)(&emu->register_mutex);
__snd_emux_dec_count(emu);
- mutex_unlock(&emu->register_mutex);
}
/*
@@ -316,10 +311,9 @@ snd_emux_use(void *private_data, struct snd_seq_port_subscribe *info)
if (snd_BUG_ON(!emu))
return -EINVAL;
- mutex_lock(&emu->register_mutex);
+ guard(mutex)(&emu->register_mutex);
snd_emux_init_port(p);
__snd_emux_inc_count(emu);
- mutex_unlock(&emu->register_mutex);
return 0;
}
@@ -339,10 +333,9 @@ snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *info)
if (snd_BUG_ON(!emu))
return -EINVAL;
- mutex_lock(&emu->register_mutex);
+ guard(mutex)(&emu->register_mutex);
snd_emux_sounds_off_all(p);
__snd_emux_dec_count(emu);
- mutex_unlock(&emu->register_mutex);
return 0;
}
diff --git a/sound/synth/util_mem.c b/sound/synth/util_mem.c
index 304a8f1740c3..2fd577c2a8eb 100644
--- a/sound/synth/util_mem.c
+++ b/sound/synth/util_mem.c
@@ -124,11 +124,8 @@ __snd_util_memblk_new(struct snd_util_memhdr *hdr, unsigned int units,
struct snd_util_memblk *
snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size)
{
- struct snd_util_memblk *blk;
- mutex_lock(&hdr->block_mutex);
- blk = __snd_util_mem_alloc(hdr, size);
- mutex_unlock(&hdr->block_mutex);
- return blk;
+ guard(mutex)(&hdr->block_mutex);
+ return __snd_util_mem_alloc(hdr, size);
}
@@ -153,9 +150,8 @@ int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk)
if (snd_BUG_ON(!hdr || !blk))
return -EINVAL;
- mutex_lock(&hdr->block_mutex);
+ guard(mutex)(&hdr->block_mutex);
__snd_util_mem_free(hdr, blk);
- mutex_unlock(&hdr->block_mutex);
return 0;
}
@@ -164,11 +160,8 @@ int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk)
*/
int snd_util_mem_avail(struct snd_util_memhdr *hdr)
{
- unsigned int size;
- mutex_lock(&hdr->block_mutex);
- size = hdr->size - hdr->used;
- mutex_unlock(&hdr->block_mutex);
- return size;
+ guard(mutex)(&hdr->block_mutex);
+ return hdr->size - hdr->used;
}