public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] riptide: clean up while loop
@ 2010-03-03  7:13 Dan Carpenter
  2010-03-03 21:51 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2010-03-03  7:13 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: Takashi Iwai, alsa-devel, kernel-janitors

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 <error27@gmail.com>

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");
 }

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch] riptide: clean up while loop
  2010-03-03  7:13 [patch] riptide: clean up while loop Dan Carpenter
@ 2010-03-03 21:51 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2010-03-03 21:51 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: alsa-devel, kernel-janitors

At Wed, 3 Mar 2010 10:13:49 +0300,
Dan Carpenter wrote:
> 
> 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 <error27@gmail.com>

Applied now.  Thanks.


Takashi

> 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");
>  }
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-03-03 21:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-03  7:13 [patch] riptide: clean up while loop Dan Carpenter
2010-03-03 21:51 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox