From 8320ba0ce534dea603b7ba22f484ee39ef2ce746 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 18 Jul 2023 16:12:58 +0200 Subject: [PATCH] ALSA: control: Add lockdep warning to internal functions To assure the proper locking, add the lockdep check to __snd_ctl_remove(), __snd_ctl_add_replace() and other internal functions to handle user controls. Link: https://lore.kernel.org/r/20230718141304.1032-6-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/core/control.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sound/core/control.c b/sound/core/control.c index 9c933350ec6b..8aaa2a84a670 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -469,6 +469,8 @@ static int __snd_ctl_add_replace(struct snd_card *card, struct snd_kcontrol *old; int err; + lockdep_assert_held_write(&card->controls_rwsem); + id = kcontrol->id; if (id.index > UINT_MAX - kcontrol->count) return -EINVAL; @@ -578,6 +580,8 @@ static int __snd_ctl_remove(struct snd_card *card, { unsigned int idx; + lockdep_assert_held_write(&card->controls_rwsem); + if (snd_BUG_ON(!card || !kcontrol)) return -EINVAL; list_del(&kcontrol->list); @@ -1524,6 +1528,8 @@ static int replace_user_tlv(struct snd_kcontrol *kctl, unsigned int __user *buf, int i; int change; + lockdep_assert_held_write(&ue->card->controls_rwsem); + if (size > 1024 * 128) /* sane value */ return -EINVAL; @@ -1600,6 +1606,8 @@ static int snd_ctl_elem_init_enum_names(struct user_element *ue) unsigned int i; const uintptr_t user_ptrval = ue->info.value.enumerated.names_ptr; + lockdep_assert_held_write(&ue->card->controls_rwsem); + buf_len = ue->info.value.enumerated.names_length; if (buf_len > 64 * 1024) return -EINVAL; @@ -1904,6 +1912,8 @@ static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file, struct snd_ctl_elem_id id; struct snd_kcontrol_volatile *vd; + lockdep_assert_held(&file->card->controls_rwsem); + if (copy_from_user(&header, buf, sizeof(header))) return -EFAULT;