aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2015-04-11 04:41:04 -0400
committerTakashi Iwai <tiwai@suse.de>2015-04-11 11:35:17 -0400
commitcab2ed7474bffafd2a68a885e03b85526194abcd (patch)
treea9e1e2008fec076254277095f21f3b947e52c423
parentc378c3b03c8d6eef2d2600d0279e2c718d6a0a44 (diff)
ALSA: ctl: fill identical information to return value when adding userspace elements
currently some members related identical information are not fiiled in returned parameter of SNDRV_CTL_IOCTL_ELEM_ADD. This is not better for userspace application. This commit copies information to returned value. When failing to copy into userspace, the added elements are going to be removed. Then, no applications can lock these elements between adding and removing because these are already locked. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/core/control.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/sound/core/control.c b/sound/core/control.c
index a750846514dc..ccb1ca26a71e 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -1214,6 +1214,7 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
1214 unsigned int access; 1214 unsigned int access;
1215 long private_size; 1215 long private_size;
1216 struct user_element *ue; 1216 struct user_element *ue;
1217 unsigned int offset;
1217 int err; 1218 int err;
1218 1219
1219 if (!*info->id.name) 1220 if (!*info->id.name)
@@ -1316,6 +1317,15 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
1316 err = snd_ctl_add(card, kctl); 1317 err = snd_ctl_add(card, kctl);
1317 if (err < 0) 1318 if (err < 0)
1318 return err; 1319 return err;
1320 offset = snd_ctl_get_ioff(kctl, &info->id);
1321 snd_ctl_build_ioff(&info->id, kctl, offset);
1322 /*
1323 * Here we cannot fill any field for the number of elements added by
1324 * this operation because there're no specific fields. The usage of
1325 * 'owner' field for this purpose may cause any bugs to userspace
1326 * applications because the field originally means PID of a process
1327 * which locks the element.
1328 */
1319 1329
1320 down_write(&card->controls_rwsem); 1330 down_write(&card->controls_rwsem);
1321 card->user_ctl_count++; 1331 card->user_ctl_count++;
@@ -1328,9 +1338,19 @@ static int snd_ctl_elem_add_user(struct snd_ctl_file *file,
1328 struct snd_ctl_elem_info __user *_info, int replace) 1338 struct snd_ctl_elem_info __user *_info, int replace)
1329{ 1339{
1330 struct snd_ctl_elem_info info; 1340 struct snd_ctl_elem_info info;
1341 int err;
1342
1331 if (copy_from_user(&info, _info, sizeof(info))) 1343 if (copy_from_user(&info, _info, sizeof(info)))
1332 return -EFAULT; 1344 return -EFAULT;
1333 return snd_ctl_elem_add(file, &info, replace); 1345 err = snd_ctl_elem_add(file, &info, replace);
1346 if (err < 0)
1347 return err;
1348 if (copy_to_user(_info, &info, sizeof(info))) {
1349 snd_ctl_remove_user_ctl(file, &info.id);
1350 return -EFAULT;
1351 }
1352
1353 return 0;
1334} 1354}
1335 1355
1336static int snd_ctl_elem_remove(struct snd_ctl_file *file, 1356static int snd_ctl_elem_remove(struct snd_ctl_file *file,