All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>,
	dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	Ben Dooks <ben-Y5A6D6n0/KfQXOPxS62xeg@public.gmane.org>
Cc: kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Roel Kluin <12o3l-IWqWACnzNjzz+pZb47iToQ@public.gmane.org>,
	kernelnewbies-bounce-qDhp9YYfzQpg9hUCZPvPmw@public.gmane.org
Subject: Re: script to find incorrect tests on unsigneds
Date: Sat, 19 Apr 2008 14:24:44 +0000	[thread overview]
Message-ID: <20080419142444.GL20637@parisc-linux.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0804182101200.14832-QfmoRoYWmW9knbxzx/v8hQ@public.gmane.org>

On Fri, Apr 18, 2008 at 09:08:55PM +0200, Julia Lawall wrote:
> I found 63 occurrences of this problem with the following semantic match
> (http://www.emn.fr/x-info/coccinelle/):
> 
> @@ unsigned int i; @@
> 
> * i < 0
> 
> I looked through all of the results by hand, and they all seem to be 
> problems.  In many cases, it seems like the variable should not be 
> unsigned as it is used to hold the return value of a function that might 
> return a negative error code, but I haven't looked into this in detail.
> 
> In the output below, the lines that begin with a single start contain a 
> test of whether an unsigned variable or structure field is less than 0.
> The output is actually generated with diff, but I converted the -s to *s 
> to avoid confusion.

> diff -u -p a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
> *** a/drivers/spi/spi_s3c24xx.c 2008-03-12 14:13:14.000000000 +0100
> @@ -127,7 +127,7 @@ static int s3c24xx_spi_setupxfer(struct 
>  
>  	div = (div / 2) - 1;
>  
> *	if (div < 0)
>  		div = 1;
>  
>  	if (div > 255)

Since this one's always in the range 0-255, it could probably be made
signed, but it's just as easy to make it work unsigned.

Reported-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>

diff --git a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
index b7476b8..b398cc9 100644
--- a/drivers/spi/spi_s3c24xx.c
+++ b/drivers/spi/spi_s3c24xx.c
@@ -125,10 +125,10 @@ static int s3c24xx_spi_setupxfer(struct spi_device *spi,
 	/* is clk = pclk / (2 * (pre+1)), or is it
 	 *    clk = (pclk * 2) / ( pre + 1) */
 
-	div = (div / 2) - 1;
+	div /= 2;
 
-	if (div < 0)
-		div = 1;
+	if (div > 0)
+		div -= 1;
 
 	if (div > 255)
 		div = 255;

-- 
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

WARNING: multiple messages have this Message-ID (diff)
From: Matthew Wilcox <matthew-Ztpu424NOJ8@public.gmane.org>
To: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>,
	dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	Ben Dooks <ben-Y5A6D6n0/KfQXOPxS62xeg@public.gmane.org>
Cc: kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Roel Kluin <12o3l-IWqWACnzNjzz+pZb47iToQ@public.gmane.org>,
	kernelnewbies-bounce-qDhp9YYfzQpg9hUCZPvPmw@public.gmane.org
Subject: Re: script to find incorrect tests on unsigneds
Date: Sat, 19 Apr 2008 08:24:44 -0600	[thread overview]
Message-ID: <20080419142444.GL20637@parisc-linux.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0804182101200.14832-QfmoRoYWmW9knbxzx/v8hQ@public.gmane.org>

On Fri, Apr 18, 2008 at 09:08:55PM +0200, Julia Lawall wrote:
> I found 63 occurrences of this problem with the following semantic match
> (http://www.emn.fr/x-info/coccinelle/):
> 
> @@ unsigned int i; @@
> 
> * i < 0
> 
> I looked through all of the results by hand, and they all seem to be 
> problems.  In many cases, it seems like the variable should not be 
> unsigned as it is used to hold the return value of a function that might 
> return a negative error code, but I haven't looked into this in detail.
> 
> In the output below, the lines that begin with a single start contain a 
> test of whether an unsigned variable or structure field is less than 0.
> The output is actually generated with diff, but I converted the -s to *s 
> to avoid confusion.

> diff -u -p a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
> *** a/drivers/spi/spi_s3c24xx.c 2008-03-12 14:13:14.000000000 +0100
> @@ -127,7 +127,7 @@ static int s3c24xx_spi_setupxfer(struct 
>  
>  	div = (div / 2) - 1;
>  
> *	if (div < 0)
>  		div = 1;
>  
>  	if (div > 255)

Since this one's always in the range 0-255, it could probably be made
signed, but it's just as easy to make it work unsigned.

Reported-by: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>
Signed-off-by: Matthew Wilcox <willy-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>

diff --git a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
index b7476b8..b398cc9 100644
--- a/drivers/spi/spi_s3c24xx.c
+++ b/drivers/spi/spi_s3c24xx.c
@@ -125,10 +125,10 @@ static int s3c24xx_spi_setupxfer(struct spi_device *spi,
 	/* is clk = pclk / (2 * (pre+1)), or is it
 	 *    clk = (pclk * 2) / ( pre + 1) */
 
-	div = (div / 2) - 1;
+	div /= 2;
 
-	if (div < 0)
-		div = 1;
+	if (div > 0)
+		div -= 1;
 
 	if (div > 255)
 		div = 255;

-- 
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

  parent reply	other threads:[~2008-04-19 14:24 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-18 16:15 script to find incorrect tests on unsigneds Roel Kluin
2008-04-18 19:08 ` Julia Lawall
2008-04-19 14:05   ` esp_scsi incorrect unsigned test Matthew Wilcox
2008-04-19 14:05     ` Matthew Wilcox
2008-04-19 14:16     ` James Bottomley
2008-04-19 14:16       ` James Bottomley
2008-04-20  0:59       ` David Miller
2008-04-20  0:59         ` David Miller
2008-04-19 14:17   ` u14-3f " Matthew Wilcox
2008-04-19 14:17     ` Matthew Wilcox
     [not found]   ` <Pine.LNX.4.64.0804182101200.14832-QfmoRoYWmW9knbxzx/v8hQ@public.gmane.org>
2008-04-19 14:24     ` Matthew Wilcox [this message]
2008-04-19 14:24       ` script to find incorrect tests on unsigneds Matthew Wilcox
2008-04-19 14:49   ` Matthew Wilcox
2008-04-19 14:49     ` Matthew Wilcox
2008-04-18 19:36 ` Julia Lawall
2008-04-19 13:29 ` walter harms
2008-04-19 13:43 ` Matthew Wilcox
2008-04-19 15:20 ` Julia Lawall
2008-04-19 15:43 ` Julia Lawall
2008-04-22 21:06 ` Julia Lawall
2008-04-22 21:28 ` Roel Kluin
2008-04-23  5:47 ` Julia Lawall
2008-04-23  9:26 ` Roel Kluin
2008-04-23  9:30 ` Roel Kluin
2008-04-23  9:54 ` Julia Lawall
2008-04-23 10:02 ` Julia Lawall
2008-04-23 10:26 ` Roel Kluin
2008-04-23 14:02 ` Roel Kluin
2008-04-23 14:05 ` Roel Kluin
2008-04-23 14:11 ` Roel Kluin
2008-04-23 14:24 ` Julia Lawall
2008-04-23 16:01 ` Roel Kluin
2008-04-23 17:59 ` Roel Kluin
2008-04-23 18:58 ` Julia Lawall
2008-04-23 19:12 ` Julia Lawall
2008-04-23 19:36 ` Roel Kluin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080419142444.GL20637@parisc-linux.org \
    --to=matthew@wil.cx \
    --cc=12o3l-IWqWACnzNjzz+pZb47iToQ@public.gmane.org \
    --cc=ben-Y5A6D6n0/KfQXOPxS62xeg@public.gmane.org \
    --cc=dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=julia-dAYI7NvHqcQ@public.gmane.org \
    --cc=kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=kernelnewbies-bounce-qDhp9YYfzQpg9hUCZPvPmw@public.gmane.org \
    --cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.