diff options
author | Takashi Iwai <tiwai@suse.de> | 2024-02-27 11:52:50 +0300 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2024-02-28 17:01:21 +0300 |
commit | 471be437be779a028040afc151972e3125b5b23c (patch) | |
tree | 810286c732b2b3c99f7cafa4c68945618656ebcb /sound/core/control_compat.c | |
parent | 2dc49651fca1e8ecd6c177cd9b576a26761a5cdf (diff) | |
download | linux-471be437be779a028040afc151972e3125b5b23c.tar.xz |
ALSA: control: Use guard() for locking
We can simplify the code gracefully with new guard() macro and co for
automatic cleanup of locks.
The lops calls under multiple rwsems are factored out as a simple
macro, so that it can be called easily from snd_ctl_dev_register()
and snd_ctl_dev_disconnect().
There are a few remaining explicit rwsem and spinlock calls, and those
are the places where the lock downgrade happens or where the temporary
unlock/relocking happens -- which guard() doens't cover well yet.
Only the code refactoring, and no functional changes.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20240227085306.9764-9-tiwai@suse.de
Diffstat (limited to 'sound/core/control_compat.c')
-rw-r--r-- | sound/core/control_compat.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/sound/core/control_compat.c b/sound/core/control_compat.c index 8392183c77ed..934bb945e702 100644 --- a/sound/core/control_compat.c +++ b/sound/core/control_compat.c @@ -167,23 +167,18 @@ static int get_ctl_type(struct snd_card *card, struct snd_ctl_elem_id *id, struct snd_ctl_elem_info *info __free(kfree) = NULL; int err; - down_read(&card->controls_rwsem); + guard(rwsem_read)(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, id); - if (! kctl) { - up_read(&card->controls_rwsem); + if (!kctl) return -ENOENT; - } info = kzalloc(sizeof(*info), GFP_KERNEL); - if (info == NULL) { - up_read(&card->controls_rwsem); + if (info == NULL) return -ENOMEM; - } info->id = *id; err = snd_power_ref_and_wait(card); if (!err) err = kctl->info(kctl, info); snd_power_unref(card); - up_read(&card->controls_rwsem); if (err >= 0) { err = info->type; *countp = info->count; @@ -451,16 +446,13 @@ static inline long snd_ctl_ioctl_compat(struct file *file, unsigned int cmd, uns #endif /* CONFIG_X86_X32_ABI */ } - down_read(&snd_ioctl_rwsem); + guard(rwsem_read)(&snd_ioctl_rwsem); list_for_each_entry(p, &snd_control_compat_ioctls, list) { if (p->fioctl) { err = p->fioctl(ctl->card, ctl, cmd, arg); - if (err != -ENOIOCTLCMD) { - up_read(&snd_ioctl_rwsem); + if (err != -ENOIOCTLCMD) return err; - } } } - up_read(&snd_ioctl_rwsem); return -ENOIOCTLCMD; } |