ALSA: control: Add lockdep warning to internal functions
authorTakashi Iwai <tiwai@suse.de>
Tue, 18 Jul 2023 14:12:58 +0000 (16:12 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 20 Jul 2023 08:01:40 +0000 (10:01 +0200)
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 <tiwai@suse.de>
sound/core/control.c

index 9c933350ec6baa8de623d2c8197c45c1006d0587..8aaa2a84a670bd0b24362be42c99c4e6e24fb868 100644 (file)
@@ -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;