From 7378bc2f19f841b25f1e27c7abce1ecc298f71f1 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 26 Jun 2015 06:59:57 +0200 Subject: [PATCH] ALSA: jack: Fix endless loop at unique index detection MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit While the commit [d0a601c278de: ALSA: jack: Fix the id uniqueness check] fixes the wrong string check, it leads to a worse result -- the loop in get_available_index() goes into an endless loop. The cause is that snd_ctl_find_id() returns the object assigned to the numid if it's set. Thus it points to the previous entry again. This patch clears the numid field for the next call properly. Reported-and-tested-by: Tomáš Pružina Signed-off-by: Takashi Iwai --- sound/core/ctljack.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sound/core/ctljack.c b/sound/core/ctljack.c index 9149a4aefa95..84a3cd683068 100644 --- a/sound/core/ctljack.c +++ b/sound/core/ctljack.c @@ -41,8 +41,11 @@ static int get_available_index(struct snd_card *card, const char *name) sid.iface = SNDRV_CTL_ELEM_IFACE_CARD; strlcpy(sid.name, name, sizeof(sid.name)); - while (snd_ctl_find_id(card, &sid)) + while (snd_ctl_find_id(card, &sid)) { sid.index++; + /* reset numid; otherwise snd_ctl_find_id() hits this again */ + sid.numid = 0; + } return sid.index; } -- 2.34.1