From 7378bc2f19f841b25f1e27c7abce1ecc298f71f1 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 26 Jun 2015 06:59:57 +0200 Subject: ALSA: jack: Fix endless loop at unique index detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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(-) (limited to 'sound/core') 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; } -- cgit v1.2.3-58-ga151 From 0755e74b8f04d17cea09fa342a788025b2b50e2e Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Mon, 29 Jun 2015 17:10:22 +0100 Subject: ALSA: Fix uninintialized error return Static analysis with cppcheck found the following error: [sound/core/init.c:118]: (error) Uninitialized variable: err ..this was introduced by commit 2471b6c80a70e80de69f5ff4c37187c3912e5874 ("ALSA: info: Register proc entries recursively, too") where the call to snd_info_card_register was removed and no longer setting the error return in err. When snd_info_create_card_entry fails to allocate a an entry, the error path exits with garbage in err. Fix is to return -ENOMEM if entry fails to be allocated. Fixes: 2471b6c80a ("ALSA: info: Register proc entries recursively, too") Signed-off-by: Colin Ian King Signed-off-by: Takashi Iwai --- sound/core/init.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'sound/core') diff --git a/sound/core/init.c b/sound/core/init.c index 3e0cebacefe1..20f37fb3800e 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -109,13 +109,12 @@ static void snd_card_id_read(struct snd_info_entry *entry, static int init_info_for_card(struct snd_card *card) { - int err; struct snd_info_entry *entry; entry = snd_info_create_card_entry(card, "id", card->proc_root); if (!entry) { dev_dbg(card->dev, "unable to create card entry\n"); - return err; + return -ENOMEM; } entry->c.text.read = snd_card_id_read; card->proc_id = entry; -- cgit v1.2.3-58-ga151