* ehci tests unsigned variables against 0
@ 2008-04-19 14:58 Matthew Wilcox
2008-04-21 19:26 ` David Brownell
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Matthew Wilcox @ 2008-04-19 14:58 UTC (permalink / raw)
To: kernel-janitors
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/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
> *** a/drivers/usb/host/ehci-dbg.c 2008-03-12 14:13:14.000000000 +0100
> @@ -454,7 +454,7 @@ static void qh_lines (
> (scratch >> 16) & 0x7fff,
> scratch,
> td->urb);
> * if (temp < 0)
> temp = 0;
> else if (size < temp)
> temp = size;
> @@ -465,7 +465,7 @@ static void qh_lines (
> }
>
> temp = snprintf (next, size, "\n");
> * if (temp < 0)
> temp = 0;
> else if (size < temp)
> temp = size;
These tests will never trigger and should simply be removed. Linux's
kernel snprintf function conforms to C99 and never returns 0.
--
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."
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: ehci tests unsigned variables against 0
2008-04-19 14:58 ehci tests unsigned variables against 0 Matthew Wilcox
@ 2008-04-21 19:26 ` David Brownell
2008-04-21 20:02 ` Matthew Wilcox
2008-04-21 20:14 ` David Brownell
2 siblings, 0 replies; 4+ messages in thread
From: David Brownell @ 2008-04-21 19:26 UTC (permalink / raw)
To: kernel-janitors
On Saturday 19 April 2008, Matthew Wilcox wrote:
> These tests will never trigger and should simply be removed. Linux's
> kernel snprintf function conforms to C99 and never returns 0.
I think you mean "never returns negative" ?
-ENOPATCH
... although if that's the case, I'd think that the *snprintf()
signatures are incorrect: they should return "unsigned" not "int".
If that were done, I think even GCC could be made to report such
issues; one wouldn't need less-common tools like coccinelle.
(What I've seen of coccinelle makes me glad it's being applied to
the kernel sources, by the way.)
- Dave
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ehci tests unsigned variables against 0
2008-04-19 14:58 ehci tests unsigned variables against 0 Matthew Wilcox
2008-04-21 19:26 ` David Brownell
@ 2008-04-21 20:02 ` Matthew Wilcox
2008-04-21 20:14 ` David Brownell
2 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2008-04-21 20:02 UTC (permalink / raw)
To: kernel-janitors
On Mon, Apr 21, 2008 at 12:26:10PM -0700, David Brownell wrote:
> On Saturday 19 April 2008, Matthew Wilcox wrote:
> > These tests will never trigger and should simply be removed. ?Linux's
> > kernel snprintf function conforms to C99 and never returns 0.
>
> I think you mean "never returns negative" ?
True.
> -ENOPATCH
Yeah ... I didn't bother with one. Let's try now:
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 64ebfc5..55a2c73 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -454,9 +454,7 @@ static void qh_lines (
(scratch >> 16) & 0x7fff,
scratch,
td->urb);
- if (temp < 0)
- temp = 0;
- else if (size < temp)
+ if (size < temp)
temp = size;
size -= temp;
next += temp;
@@ -465,9 +463,7 @@ static void qh_lines (
}
temp = snprintf (next, size, "\n");
- if (temp < 0)
- temp = 0;
- else if (size < temp)
+ if (size < temp)
temp = size;
size -= temp;
next += temp;
> ... although if that's the case, I'd think that the *snprintf()
> signatures are incorrect: they should return "unsigned" not "int".
> If that were done, I think even GCC could be made to report such
> issues; one wouldn't need less-common tools like coccinelle.
We can take it up with ANSI, but I'm not sure they'll be interested in
changing the return type of snprintf ...
> (What I've seen of coccinelle makes me glad it's being applied to
> the kernel sources, by the way.)
Me too!
--
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."
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: ehci tests unsigned variables against 0
2008-04-19 14:58 ehci tests unsigned variables against 0 Matthew Wilcox
2008-04-21 19:26 ` David Brownell
2008-04-21 20:02 ` Matthew Wilcox
@ 2008-04-21 20:14 ` David Brownell
2 siblings, 0 replies; 4+ messages in thread
From: David Brownell @ 2008-04-21 20:14 UTC (permalink / raw)
To: kernel-janitors
On Monday 21 April 2008, Matthew Wilcox wrote:
> > -ENOPATCH
>
> Yeah ... I didn't bother with one. Let's try now:
If you send this as a proper patch to linux-usb@vger,
you can add
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
>
> diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
> index 64ebfc5..55a2c73 100644
> --- a/drivers/usb/host/ehci-dbg.c
> +++ b/drivers/usb/host/ehci-dbg.c
> @@ -454,9 +454,7 @@ static void qh_lines (
> (scratch >> 16) & 0x7fff,
> scratch,
> td->urb);
> - if (temp < 0)
> - temp = 0;
> - else if (size < temp)
> + if (size < temp)
> temp = size;
> size -= temp;
> next += temp;
> @@ -465,9 +463,7 @@ static void qh_lines (
> }
>
> temp = snprintf (next, size, "\n");
> - if (temp < 0)
> - temp = 0;
> - else if (size < temp)
> + if (size < temp)
> temp = size;
> size -= temp;
> next += temp;
>
> > ... although if that's the case, I'd think that the *snprintf()
> > signatures are incorrect: they should return "unsigned" not "int".
> > If that were done, I think even GCC could be made to report such
> > issues; one wouldn't need less-common tools like coccinelle.
>
> We can take it up with ANSI, but I'm not sure they'll be interested in
> changing the return type of snprintf ...
I don't care so much about ANSI as about <linux/kernel.h>,
at least in this context...
- Dave
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-04-21 20:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-19 14:58 ehci tests unsigned variables against 0 Matthew Wilcox
2008-04-21 19:26 ` David Brownell
2008-04-21 20:02 ` Matthew Wilcox
2008-04-21 20:14 ` David Brownell
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.