linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [resend][PATCH] avoid signed vs unsigned comparison in efi_range_is_wc()
@ 2005-06-16 20:21 Jesper Juhl
  2005-06-16 20:41 ` Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Jesper Juhl @ 2005-06-16 20:21 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Walt Drummond, David Mosberger-Tang, Stephane Eranian, linux-kernel

I send in the patch below a while back but never recieved any response.
Now I'm resending it in the hope that it might be added to -mm.
The patch still applies cleanly to 2.6.12-rc6-mm1

-- 
Jesper Juhl


---------- Forwarded message ----------
Date: Fri, 18 Mar 2005 00:43:33 +0100 (CET)
From: Jesper Juhl <juhl-lkml@dif.dk>
To: linux-kernel <linux-kernel@vger.kernel.org>
Cc: Walt Drummond <drummond@valinux.com>,
    David Mosberger-Tang <davidm@hpl.hp.com>,
    Stephane Eranian <eranian@hpl.hp.com>
Subject: [PATCH] avoid signed vs unsigned comparison in efi_range_is_wc()


This little function in include/linux/efi.h :

static inline int efi_range_is_wc(unsigned long start, unsigned long len)
{
        int i;

        for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
                unsigned long paddr = __pa(start + i);
                if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
                        return 0;
        }
        /* The range checked out */
        return 1;
}

generates this warning when building with gcc -W : 

include/linux/efi.h: In function `efi_range_is_wc':
include/linux/efi.h:320: warning: comparison between signed and unsigned

It looks to me like a significantly large 'len' passed in could cause the 
loop to never end. Isn't it safer to make 'i' an unsigned long as well? 
Like this little patch below (which of course also kills the warning) :


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

diff -up linux-2.6.11-mm4-orig/include/linux/efi.h linux-2.6.11-mm4/include/linux/efi.h
--- linux-2.6.11-mm4-orig/include/linux/efi.h	2005-03-16 15:45:35.000000000 +0100
+++ linux-2.6.11-mm4/include/linux/efi.h	2005-03-18 00:34:36.000000000 +0100
@@ -315,7 +315,7 @@ extern struct efi_memory_map memmap;
  */
 static inline int efi_range_is_wc(unsigned long start, unsigned long len)
 {
-	int i;
+	unsigned long i;
 
 	for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
 		unsigned long paddr = __pa(start + i);





^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: [resend][PATCH] avoid signed vs unsigned comparison in efi_range_is_wc()
@ 2005-06-17  0:25 Arnd Bergmann <arnd@arndb.de>
  2005-06-17 17:04 ` Jesper Juhl
  0 siblings, 1 reply; 12+ messages in thread
From: Arnd Bergmann <arnd@arndb.de> @ 2005-06-17  0:25 UTC (permalink / raw)
  To: arnd, akpm, linux-kernel, eranian, davidm, juhl-lkml

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

Jesper wrote:

>> Jesper, are you interested in my stuff
>
>Certainly.
>

Ok, here is the warning level patch for reference. I'm sending the rest of my stuff
to you off-list since it is rather largish and I don't have a working mail client
on this machine.

      Arnd <><

[-- Attachment #2: warn-levels.diff --]
[-- Type: application/octet-stream, Size: 5116 bytes --]

[PATCH] kbuild: selectable warning levels

This introduces four different levels of compiler warnings to the
kernel build environment. The idea is to enable developers to get the
extra static code checks that newer gcc versions provide without
annoying users with false positives.

I have tested this with gcc versions 2.95 through 4.0 on i386 as
well as some cross builds for x86_64, ppc64 and s390. The conditional
warning settings are needed to get some of the options that pre-4.0
compilers don't support.

I have not tested this at all with non-GNU compilers, so it
probably is not ready for inclusion in -mm at this point.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Index: linus-2.6/Makefile
===================================================================
--- linus-2.6.orig/Makefile	2005-06-17 00:57:11.000000000 +0200
+++ linus-2.6/Makefile	2005-06-17 01:54:36.000000000 +0200
@@ -348,8 +348,7 @@
 
 CPPFLAGS        := -D__KERNEL__ $(LINUXINCLUDE)
 
-CFLAGS 		:= -Wall -Wstrict-prototypes -Wno-trigraphs \
-	  	   -fno-strict-aliasing -fno-common \
+CFLAGS 		:= -fno-strict-aliasing -fno-common \
 		   -ffreestanding
 AFLAGS		:= -D__ASSEMBLY__
 
@@ -533,11 +532,46 @@
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
 CHECKFLAGS     += $(NOSTDINC_FLAGS)
 
+# standard warnings
+CWARN_LESS         += -Wall -Wstrict-prototypes -Wno-trigraphs
 # warn about C99 declaration after statement
-CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
+CWARN_LESS         += $(call cc-option,-Wdeclaration-after-statement,)
+CWARN_LESS_COND    +=
+ifdef CONFIG_WARN_ERROR
+CWARN_LESS         += -Werror
+endif
+ifdef CONFIG_WARN_LESS
+CWARN_LESS         += -Wno-deprecated-declarations
+CWARN_LESS_COND    += -Wno-pointer-sign
+CFLAGS             += $(CWARN_LESS) $(call cc-option,$(CWARN_LESS_COND),)
+endif
+
+# warn about common problems
+CWARN_NORMAL       += $(CWARN_LESS) -Winline -Wcast-align -Wundef -Wformat
+CWARN_NORMAL       += -Wmissing-noreturn
+CWARN_NORMAL_COND  += $(CWARN_LESS_COND) -Wdisabled-optimization
+CWARN_NORMAL_COND  += -Wmissing-format-attribute -Wendif-labels
+ifdef CONFIG_WARN_NORMAL
+CWARN_NORMAL_COND  += -Wno-pointer-sign
+CFLAGS             += $(CWARN_NORMAL) $(call cc-option,$(CWARN_NORMAL_COND),)
+endif
 
-# disable pointer signedness warnings in gcc 4.0
-CFLAGS += $(call cc-option,-Wno-pointer-sign,)
+# these can get rather noisy
+CWARN_MORE         += $(CWARN_NORMAL) -Wredundant-decls -Wnested-externs
+CWARN_MORE         += -Wmissing-prototypes -Wwrite-strings -Wshadow
+CWARN_MORE_COND    += $(CWARN_NORMAL_COND)
+ifdef CONFIG_WARN_MORE
+CFLAGS             += $(CWARN_MORE) $(call cc-option,$(CWARN_MORE_COND),)
+endif
+
+# these usually don't do any good
+CWARN_TOOMUCH      += $(CWARN_MORE) -Waggregate-return -Wsign-compare
+CWARN_TOOMUCH      += -W -Wlarger-than-8192 -Wconversion -Wbad-function-cast
+CWARN_TOOMUCH      += -Wcast-qual
+CWARN_TOOMUCH_COND += $(CWARN_MORE_COND) -Wpadded -Wpacked -Wunreachable-code
+ifdef CONFIG_WARN_TOOMUCH
+CFLAGS             += $(CWARN_TOOMUCH) $(call cc-option,$(CWARN_TOOMUCH_COND),)
+endif
 
 # Default kernel image to build when no specific target is given.
 # KBUILD_IMAGE may be overruled on the commandline or
Index: linus-2.6/lib/Kconfig.debug
===================================================================
--- linus-2.6.orig/lib/Kconfig.debug	2005-06-17 00:57:11.000000000 +0200
+++ linus-2.6/lib/Kconfig.debug	2005-06-17 01:52:22.000000000 +0200
@@ -159,3 +159,49 @@
 	  If you don't debug the kernel, you can say N, but we may not be able
 	  to solve problems without frame pointers.
 
+choice
+	prompt "Compiler warning level"
+	default WARN_NORMAL
+	help
+	  Select how much the compiler should warn about kernel code.
+	  If unsure, select "Normal".
+
+config WARN_LESS
+	bool "Minimal"
+	help
+	  In minimal warning mode, only the traditional -Wall warnings are
+	  enabled, with the exception of deprecated interfaces. For common
+	  configurations, there ought to be no warnings at this level.
+	  Select this if you also want to built with -Werror.
+
+config WARN_NORMAL
+	bool "Normal"
+	help
+	  The normal warning level will warn about some common problems that
+	  may need to be fixed up. If you are maintaining code that is
+	  warned about at this level, you should try to fix that.
+
+config WARN_MORE
+	bool "More"
+	help
+	  Select "More" to enable some warnings that are rather noisy for
+	  existing parts of the kernel. This is most useful to check new code
+	  before it is submitted for inclusion.
+
+config WARN_TOOMUCH
+	bool "All"
+	help
+	  Enabling all warnings will create many warnings about good code that
+	  becomes less readable if you try to work around the warning. Patches
+	  to shut up warnings at this level are likely to be rejected unless
+	  they fix real problems.
+
+endchoice
+
+config WARN_ERROR
+	bool "Make all build warnings errors"
+	depends on WARN_LESS
+	help
+	  When this option is enabled, all compiler warnings are turned into
+	  errors, making it impossible to build the kernel while some warnings
+	  are left.

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

end of thread, other threads:[~2005-06-20 17:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-16 20:21 [resend][PATCH] avoid signed vs unsigned comparison in efi_range_is_wc() Jesper Juhl
2005-06-16 20:41 ` Andrew Morton
2005-06-16 21:02   ` Jesper Juhl
2005-06-16 21:48     ` Arnd Bergmann
2005-06-16 22:24       ` Jesper Juhl
2005-06-16 20:45 ` Richard B. Johnson
2005-06-16 21:07   ` Jesper Juhl
2005-06-16 21:32     ` Arnd Bergmann
2005-06-16 21:01 ` David Mosberger
2005-06-20 17:00   ` Jesse Barnes
2005-06-17  0:25 Arnd Bergmann <arnd@arndb.de>
2005-06-17 17:04 ` Jesper Juhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).