[alsa-devel] [PATCH] ALSA: control: fix failure to return numerical ID in event data

Takashi Sakamoto o-takashi at sakamocchi.jp
Sun Feb 8 11:28:56 CET 2015


Currently an instance of control has zero as its member for numerical
ID even if any IDs are assigned to. According to this bug, any userspace
applications cannot identify controls by the ID when handling any events.
On the other hand, the other members such as name are still valid,
therefore applications can identify controls without fixing this.

This is not preferable because the ID has an advantage to allow userspace
applications to distinguish each controls by itself, without any
combinations.

Signed-off-by: Takashi Sakamoto <o-takashi at sakamocchi.jp>
---
 sound/core/control.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/sound/core/control.c b/sound/core/control.c
index 60caba1..d482997 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -352,6 +352,9 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
 	if (id.index > UINT_MAX - kcontrol->count)
 		goto error;
 
+	/* Any ID numbers are not assigned to this control yet. */
+	id.numid = 0;
+
 	down_write(&card->controls_rwsem);
 	if (snd_ctl_find_id(card, &id)) {
 		up_write(&card->controls_rwsem);
@@ -369,12 +372,17 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
 		err = -ENOMEM;
 		goto error;
 	}
-	list_add_tail(&kcontrol->list, &card->controls);
-	card->controls_count += kcontrol->count;
+
+	/* Now this control is allowed to have ID number. */
 	kcontrol->id.numid = card->last_numid + 1;
 	card->last_numid += kcontrol->count;
-	count = kcontrol->count;
+	card->controls_count += kcontrol->count;
+	list_add_tail(&kcontrol->list, &card->controls);
+
 	up_write(&card->controls_rwsem);
+
+	id = kcontrol->id;
+	count = kcontrol->count;
 	for (idx = 0; idx < count; idx++, id.index++, id.numid++)
 		snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_ADD, &id);
 	return 0;
-- 
2.1.0



More information about the Alsa-devel mailing list