public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix gcc -W warning in netdevice.h
@ 2005-06-15 23:01 Jesper Juhl
  2005-06-16  7:13 ` Mikael Pettersson
  0 siblings, 1 reply; 3+ messages in thread
From: Jesper Juhl @ 2005-06-15 23:01 UTC (permalink / raw)
  To: LKML
  Cc: David S. Miller, Corey Minyard, Donald J. Becker, Alan Cox,
	Bjorn Ekwall., Pekka Riikonen

This might be a slightly controversial patch in that it adds a cast purely 
to shut up a gcc -W warning, but this header file is used in *lots* of 
places, so when building with gcc -W this warning shows up all over the 
place :
	include/linux/netdevice.h:781: warning: comparison between signed and unsigned
With my normal .config I over 120 instances of this one, so shutting it up 
cuts down on the stuff I have to wade through to try and spot real 
potential problems quite a bit.
The cast is completely harmless since the unsigned value that gcc is 
complaining about will never exceed the storage capacity of a plain int, 
and it will not change any actual code behaviour.

Please consider merging.


Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
---

 include/linux/netdevice.h |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

--- linux-2.6.12-rc6-mm1-orig/include/linux/netdevice.h	2005-06-12 15:58:58.000000000 +0200
+++ linux-2.6.12-rc6-mm1/include/linux/netdevice.h	2005-06-16 00:52:14.000000000 +0200
@@ -778,7 +778,7 @@ enum {
 static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
 {
 	/* use default */
-	if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
+	if (debug_value < 0 || debug_value >= (int)(sizeof(u32) * 8))
 		return default_msg_enable_bits;
 	if (debug_value == 0)	/* no output */
 		return 0;




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

* Re: [PATCH] fix gcc -W warning in netdevice.h
  2005-06-15 23:01 [PATCH] fix gcc -W warning in netdevice.h Jesper Juhl
@ 2005-06-16  7:13 ` Mikael Pettersson
  2005-06-16 19:09   ` Jesper Juhl
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Pettersson @ 2005-06-16  7:13 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: LKML, David S. Miller, Corey Minyard, Donald J. Becker, Alan Cox,
	Bjorn Ekwall., Pekka Riikonen

Jesper Juhl writes:
 > --- linux-2.6.12-rc6-mm1-orig/include/linux/netdevice.h	2005-06-12 15:58:58.000000000 +0200
 > +++ linux-2.6.12-rc6-mm1/include/linux/netdevice.h	2005-06-16 00:52:14.000000000 +0200
 > @@ -778,7 +778,7 @@ enum {
 >  static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
 >  {
 >  	/* use default */
 > -	if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
 > +	if (debug_value < 0 || debug_value >= (int)(sizeof(u32) * 8))
 >  		return default_msg_enable_bits;

I'd change debug_value to unsigned, and drop the "< 0" test and the
now redundant "(int)" cast. Both cleaner and faster. Win Win :-)

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

* Re: [PATCH] fix gcc -W warning in netdevice.h
  2005-06-16  7:13 ` Mikael Pettersson
@ 2005-06-16 19:09   ` Jesper Juhl
  0 siblings, 0 replies; 3+ messages in thread
From: Jesper Juhl @ 2005-06-16 19:09 UTC (permalink / raw)
  To: Mikael Pettersson
  Cc: Jesper Juhl, LKML, David S. Miller, Donald J. Becker, Alan Cox,
	Bjorn Ekwall, Pekka Riikonen, Jeff Garzik

[-- Attachment #1: Type: text/plain, Size: 2239 bytes --]

On 6/16/05, Mikael Pettersson <mikpe@csd.uu.se> wrote:
> Jesper Juhl writes:
>  > --- linux-2.6.12-rc6-mm1-orig/include/linux/netdevice.h      2005-06-12 15:58:58.000000000 +0200
>  > +++ linux-2.6.12-rc6-mm1/include/linux/netdevice.h   2005-06-16 00:52:14.000000000 +0200
>  > @@ -778,7 +778,7 @@ enum {
>  >  static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
>  >  {
>  >      /* use default */
>  > -    if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
>  > +    if (debug_value < 0 || debug_value >= (int)(sizeof(u32) * 8))
>  >              return default_msg_enable_bits;
> 
> I'd change debug_value to unsigned, and drop the "< 0" test and the
> now redundant "(int)" cast. Both cleaner and faster. Win Win :-)

Hmm, yes, even if some caller is currently passing negative values
those values would (when implicitly converted to unsigned) have a
value significantly greater than (sizeof(u32) * 8), so the first if
statement would still be true and the function would then still behave
exactely the same... nice.

Here's a patch.

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---

 include/linux/netdevice.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
      --- linux-2.6.12-rc6-mm1-orig/include/linux/netdevice.h	2005-06-12
15:58:58.000000000 +0200
+++ linux-2.6.12-rc6-mm1/include/linux/netdevice.h	2005-06-16
21:08:18.000000000 +0200
@@ -775,10 +775,10 @@ enum {
 #define netif_msg_hw(p)		((p)->msg_enable & NETIF_MSG_HW)
 #define netif_msg_wol(p)	((p)->msg_enable & NETIF_MSG_WOL)
 
-static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
+static inline u32 netif_msg_init(unsigned int debug_value, int
default_msg_enable_bits)
 {
 	/* use default */
-	if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
+	if (debug_value >= (sizeof(u32) * 8))
 		return default_msg_enable_bits;
 	if (debug_value == 0)	/* no output */
 		return 0;


(patch also attached since gmail tends to mangle inline patches - grrr)

-- 
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: netdevice_h-signed-vs-unsigned-2.patch --]
[-- Type: text/x-patch; name="netdevice_h-signed-vs-unsigned-2.patch", Size: 708 bytes --]

--- linux-2.6.12-rc6-mm1-orig/include/linux/netdevice.h	2005-06-12 15:58:58.000000000 +0200
+++ linux-2.6.12-rc6-mm1/include/linux/netdevice.h	2005-06-16 21:08:18.000000000 +0200
@@ -775,10 +775,10 @@ enum {
 #define netif_msg_hw(p)		((p)->msg_enable & NETIF_MSG_HW)
 #define netif_msg_wol(p)	((p)->msg_enable & NETIF_MSG_WOL)
 
-static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
+static inline u32 netif_msg_init(unsigned int debug_value, int default_msg_enable_bits)
 {
 	/* use default */
-	if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
+	if (debug_value >= (sizeof(u32) * 8))
 		return default_msg_enable_bits;
 	if (debug_value == 0)	/* no output */
 		return 0;

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

end of thread, other threads:[~2005-06-16 19:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-15 23:01 [PATCH] fix gcc -W warning in netdevice.h Jesper Juhl
2005-06-16  7:13 ` Mikael Pettersson
2005-06-16 19:09   ` Jesper Juhl

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