All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de
Cc: alsa-devel@alsa-project.org
Subject: [PATCH 3/4] ctl: fill identical information to return value when adding userspace elements
Date: Sat, 11 Apr 2015 17:41:04 +0900	[thread overview]
Message-ID: <1428741665-22262-4-git-send-email-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <1428741665-22262-1-git-send-email-o-takashi@sakamocchi.jp>

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>
---
 sound/core/control.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/sound/core/control.c b/sound/core/control.c
index a750846..ccb1ca2 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,
 	unsigned int access;
 	long private_size;
 	struct user_element *ue;
+	unsigned int offset;
 	int err;
 
 	if (!*info->id.name)
@@ -1316,6 +1317,15 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
 	err = snd_ctl_add(card, kctl);
 	if (err < 0)
 		return err;
+	offset = snd_ctl_get_ioff(kctl, &info->id);
+	snd_ctl_build_ioff(&info->id, kctl, offset);
+	/*
+	 * Here we cannot fill any field for the number of elements added by
+	 * this operation because there're no specific fields. The usage of
+	 * 'owner' field for this purpose may cause any bugs to userspace
+	 * applications because the field originally means PID of a process
+	 * which locks the element.
+	 */
 
 	down_write(&card->controls_rwsem);
 	card->user_ctl_count++;
@@ -1328,9 +1338,19 @@ static int snd_ctl_elem_add_user(struct snd_ctl_file *file,
 				 struct snd_ctl_elem_info __user *_info, int replace)
 {
 	struct snd_ctl_elem_info info;
+	int err;
+
 	if (copy_from_user(&info, _info, sizeof(info)))
 		return -EFAULT;
-	return snd_ctl_elem_add(file, &info, replace);
+	err = snd_ctl_elem_add(file, &info, replace);
+	if (err < 0)
+		return err;
+	if (copy_to_user(_info, &info, sizeof(info))) {
+		snd_ctl_remove_user_ctl(file, &info.id);
+		return -EFAULT;
+	}
+
+	return 0;
 }
 
 static int snd_ctl_elem_remove(struct snd_ctl_file *file,
-- 
2.1.0

  parent reply	other threads:[~2015-04-11  8:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-08 17:07 [PATCH 0/4] ALSA: ctl: fix userspace control element operations Takashi Sakamoto
2015-04-08 17:07 ` [PATCH 1/4] ALSA: ctl: confirm to return all identical information Takashi Sakamoto
2015-04-09  5:36   ` Takashi Iwai
2015-04-10 12:00     ` Takashi Sakamoto
2015-04-10 12:08       ` Takashi Iwai
2015-04-08 17:07 ` [PATCH 2/4] ALSA: ctl: fix a bug to return no identical information in Takashi Sakamoto
2015-04-08 17:07 ` [PATCH 3/4] ALSA: ctl: fill identical information to return value Takashi Sakamoto
2015-04-08 17:07 ` [PATCH 4/4] ALSA: ctl: fix to handle several elements added by Takashi Sakamoto
2015-04-11  8:41 ` [PATCH 0/4 v2] fix userspace control element operations Takashi Sakamoto
2015-04-11  8:41   ` [PATCH 1/4] ctl: confirm to return all identical information in 'activate' event Takashi Sakamoto
2015-04-11 15:40     ` Takashi Iwai
2015-04-11  8:41   ` [PATCH 2/4] ctl: fix a bug to return no identical information in info operation for userspace controls Takashi Sakamoto
2015-04-11 15:40     ` Takashi Iwai
2015-04-11  8:41   ` Takashi Sakamoto [this message]
2015-04-11 15:41     ` [PATCH 3/4] ctl: fill identical information to return value when adding userspace elements Takashi Iwai
2015-04-11  8:41   ` [PATCH 4/4] ctl: fix to handle several elements added by one operation for userspace element Takashi Sakamoto
2015-04-11 15:42     ` Takashi Iwai
2015-04-12  0:15       ` Takashi Sakamoto
2015-04-11 15:41   ` [PATCH 0/4 v2] fix userspace control element operations Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428741665-22262-4-git-send-email-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.