Re: [RFC 2/4] Alsa: control: increment index field for duplicated control.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Nov 8 2016 17:11, Arnaud Pouliquen wrote:
Instead of returning an error when a control is already present, the
index field is incremented and a warning message is printed.
This allows drivers to instanciate same control without
device and sub device number management ( MIXER type controls).

Change-Id: Ifcc60dca9d1cf4c3a424bb9653296678aa7953cb
Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@xxxxxx>
---
 sound/core/control.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/sound/core/control.c b/sound/core/control.c
index fb096cb..014e3f4 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -365,6 +365,7 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
 	struct snd_ctl_elem_id id;
 	unsigned int idx;
 	unsigned int count;
+	struct snd_kcontrol *elem_set;
 	int err = -EINVAL;

 	if (! kcontrol)
@@ -376,17 +377,24 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
 		goto error;

 	down_write(&card->controls_rwsem);
-	if (snd_ctl_find_id(card, &id)) {
-		up_write(&card->controls_rwsem);
-		dev_err(card->dev, "control %i:%i:%i:%s:%i is already present\n",
-					id.iface,
-					id.device,
-					id.subdevice,
-					id.name,
-					id.index);
-		err = -EBUSY;
-		goto error;
+	while (elem_set = snd_ctl_find_id(card, &id)) {
+		id.index++;
+		if (id.index > UINT_MAX - kcontrol->count) {
+			up_write(&card->controls_rwsem);
+			dev_err(card->dev, "no more free index for control %i:%i:%i:%s\n",
+				id.iface, id.device, id.subdevice, id.name);
+			err = -ENOSPC;
+			goto error;
+		}
+	}
+	if (kcontrol->id.index != id.index) {
+		dev_warn(card->dev, "control %i:%i:%i:%s:%i is already present\n",
+			 id.iface, id.device, id.subdevice, id.name, id.index);
+		dev_warn(card->dev, "control index updated from %i to %i\n",
+			 kcontrol->id.index, id.index);
+		kcontrol->id.index = id.index;
 	}
+
 	if (snd_ctl_find_hole(card, kcontrol->count) < 0) {
 		up_write(&card->controls_rwsem);
 		err = -ENOMEM;

As Iwai-san explained below, this integration is a bit over-specification in control core, because your issue is specific in ALSA SoC part.


On Nov 8 2016 23:30, Takashi Iwai wrote:
> Right, this behavior must be optional.  For the normal drivers, the
> duplicated controls *are* errors, and we catch it instead.  For
> drivers that are aware of confliction and want the automatic
> workaround (e.g. HD-audio driver does it already), this kind of code
> would be useful to be in the common place.
(http://mailman.alsa-project.org/pipermail/alsa-devel/2016-November/114430.html)

For drivers outside of ALSA SoC part, developers can and should program control element sets with unique identification information, because design of sound card is fixed at development time. Therefore, these codes should be in ALSA SoC core, as I introduced once.

When we have the same requirement for drivers outside of ALSA SoC part, then we're going to move these codes from ALSA SoC core to ALSA control core, I think.


Regards

Takashi Sakamoto
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux