Commit 8320ba0c authored by Takashi Iwai's avatar Takashi Iwai

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.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 192c4ccc
...@@ -469,6 +469,8 @@ static int __snd_ctl_add_replace(struct snd_card *card, ...@@ -469,6 +469,8 @@ static int __snd_ctl_add_replace(struct snd_card *card,
struct snd_kcontrol *old; struct snd_kcontrol *old;
int err; int err;
lockdep_assert_held_write(&card->controls_rwsem);
id = kcontrol->id; id = kcontrol->id;
if (id.index > UINT_MAX - kcontrol->count) if (id.index > UINT_MAX - kcontrol->count)
return -EINVAL; return -EINVAL;
...@@ -578,6 +580,8 @@ static int __snd_ctl_remove(struct snd_card *card, ...@@ -578,6 +580,8 @@ static int __snd_ctl_remove(struct snd_card *card,
{ {
unsigned int idx; unsigned int idx;
lockdep_assert_held_write(&card->controls_rwsem);
if (snd_BUG_ON(!card || !kcontrol)) if (snd_BUG_ON(!card || !kcontrol))
return -EINVAL; return -EINVAL;
list_del(&kcontrol->list); list_del(&kcontrol->list);
...@@ -1524,6 +1528,8 @@ static int replace_user_tlv(struct snd_kcontrol *kctl, unsigned int __user *buf, ...@@ -1524,6 +1528,8 @@ static int replace_user_tlv(struct snd_kcontrol *kctl, unsigned int __user *buf,
int i; int i;
int change; int change;
lockdep_assert_held_write(&ue->card->controls_rwsem);
if (size > 1024 * 128) /* sane value */ if (size > 1024 * 128) /* sane value */
return -EINVAL; return -EINVAL;
...@@ -1600,6 +1606,8 @@ static int snd_ctl_elem_init_enum_names(struct user_element *ue) ...@@ -1600,6 +1606,8 @@ static int snd_ctl_elem_init_enum_names(struct user_element *ue)
unsigned int i; unsigned int i;
const uintptr_t user_ptrval = ue->info.value.enumerated.names_ptr; 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; buf_len = ue->info.value.enumerated.names_length;
if (buf_len > 64 * 1024) if (buf_len > 64 * 1024)
return -EINVAL; return -EINVAL;
...@@ -1904,6 +1912,8 @@ static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file, ...@@ -1904,6 +1912,8 @@ static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file,
struct snd_ctl_elem_id id; struct snd_ctl_elem_id id;
struct snd_kcontrol_volatile *vd; struct snd_kcontrol_volatile *vd;
lockdep_assert_held(&file->card->controls_rwsem);
if (copy_from_user(&header, buf, sizeof(header))) if (copy_from_user(&header, buf, sizeof(header)))
return -EFAULT; return -EFAULT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment