From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Carpenter Subject: [patch] riptide: clean up while loop Date: Wed, 3 Mar 2010 10:13:49 +0300 Message-ID: <20100303071349.GG5086@bicker> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-bw0-f215.google.com (mail-bw0-f215.google.com [209.85.218.215]) by alsa0.perex.cz (Postfix) with ESMTP id 7A0EA1038AF for ; Wed, 3 Mar 2010 08:13:58 +0100 (CET) Received: by bwz7 with SMTP id 7so985217bwz.4 for ; Tue, 02 Mar 2010 23:13:58 -0800 (PST) Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Jaroslav Kysela Cc: Takashi Iwai , alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org List-Id: alsa-devel@alsa-project.org If getpaths() returned an odd number this would be a buffer under-run and an endless loop. It turns out that getpaths() can only return even numbers, but let's make it easy for people auditing code. With the new code you don't need to look at getpaths(). This silences a smatch warning. Signed-off-by: Dan Carpenter diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c index e66ef2b..a5924af 100644 --- a/sound/pci/riptide/riptide.c +++ b/sound/pci/riptide/riptide.c @@ -1974,9 +1974,9 @@ snd_riptide_proc_read(struct snd_info_entry *entry, } snd_iprintf(buffer, "Paths:\n"); i = getpaths(cif, p); - while (i--) { - snd_iprintf(buffer, "%x->%x ", p[i - 1], p[i]); - i--; + while (i >= 2) { + i -= 2; + snd_iprintf(buffer, "%x->%x ", p[i], p[i + 1]); } snd_iprintf(buffer, "\n"); } From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Carpenter Date: Wed, 03 Mar 2010 07:13:49 +0000 Subject: [patch] riptide: clean up while loop Message-Id: <20100303071349.GG5086@bicker> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Jaroslav Kysela Cc: Takashi Iwai , alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org If getpaths() returned an odd number this would be a buffer under-run and an endless loop. It turns out that getpaths() can only return even numbers, but let's make it easy for people auditing code. With the new code you don't need to look at getpaths(). This silences a smatch warning. Signed-off-by: Dan Carpenter diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c index e66ef2b..a5924af 100644 --- a/sound/pci/riptide/riptide.c +++ b/sound/pci/riptide/riptide.c @@ -1974,9 +1974,9 @@ snd_riptide_proc_read(struct snd_info_entry *entry, } snd_iprintf(buffer, "Paths:\n"); i = getpaths(cif, p); - while (i--) { - snd_iprintf(buffer, "%x->%x ", p[i - 1], p[i]); - i--; + while (i >= 2) { + i -= 2; + snd_iprintf(buffer, "%x->%x ", p[i], p[i + 1]); } snd_iprintf(buffer, "\n"); }