linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends
@ 2012-08-31 15:02 Guenter Roeck
  2012-08-31 19:38 ` Andrew Morton
  2012-09-09 14:57 ` Geert Uytterhoeven
  0 siblings, 2 replies; 9+ messages in thread
From: Guenter Roeck @ 2012-08-31 15:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Pekka Enberg, Ingo Molnar, H. Peter Anvin,
	Jean Delvare, lm-sensors, Guenter Roeck

DIV_ROUND_CLOSEST returns a bad result for negative dividends:
	DIV_ROUND_CLOSEST(-2, 2) = 0

Most of the time this does not matter. However, in the hardware monitoring
subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be
negative (such as temperatures).

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v4: Don't address negative divisors to improve chances for compile-time
    optimization. Document DIV_ROUND_CLOSEST macro.

v3: Instead of adding a new macro, fix DIV_ROUND_CLOSEST.
    This version works for negative dividend and divisor.

v2: v1 did not work if typeof(divisor) was an unsigned variable type
    (which can obviously not be negative).
    Rework to revert to DIV_ROUND_CLOSEST if the dividend is unsigned,
    or if it is signed but non-negative.

 include/linux/kernel.h |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 6043821..594b419 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -82,10 +82,18 @@
 	__x - (__x % (y));				\
 }							\
 )
+
+/*
+ * Divide positive or negative dividend by positive divisor and round
+ * to closest integer. Result is undefined for negative divisors.
+ */
 #define DIV_ROUND_CLOSEST(x, divisor)(			\
 {							\
-	typeof(divisor) __divisor = divisor;		\
-	(((x) + ((__divisor) / 2)) / (__divisor));	\
+	typeof(x) __x = x;				\
+	typeof(divisor) __d = divisor;			\
+	(((typeof(x))-1) >= 0 || (__x) >= 0) ?		\
+		(((__x) + ((__d) / 2)) / (__d)) :	\
+		(((__x) - ((__d) / 2)) / (__d));	\
 }							\
 )
 
-- 
1.7.9.7


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

* Re: [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends
  2012-08-31 15:02 [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends Guenter Roeck
@ 2012-08-31 19:38 ` Andrew Morton
  2012-08-31 21:05   ` Guenter Roeck
  2012-09-01 17:02   ` Jean Delvare
  2012-09-09 14:57 ` Geert Uytterhoeven
  1 sibling, 2 replies; 9+ messages in thread
From: Andrew Morton @ 2012-08-31 19:38 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel, Pekka Enberg, Ingo Molnar, H. Peter Anvin,
	Jean Delvare, lm-sensors

On Fri, 31 Aug 2012 08:02:19 -0700
Guenter Roeck <linux@roeck-us.net> wrote:

> DIV_ROUND_CLOSEST returns a bad result for negative dividends:
> 	DIV_ROUND_CLOSEST(-2, 2) = 0
> 
> Most of the time this does not matter. However, in the hardware monitoring
> subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be
> negative (such as temperatures).
> 
> ...
>
> +
> +/*
> + * Divide positive or negative dividend by positive divisor and round
> + * to closest integer. Result is undefined for negative divisors.
> + */
>  #define DIV_ROUND_CLOSEST(x, divisor)(			\
>  {							\
> -	typeof(divisor) __divisor = divisor;		\
> -	(((x) + ((__divisor) / 2)) / (__divisor));	\
> +	typeof(x) __x = x;				\
> +	typeof(divisor) __d = divisor;			\
> +	(((typeof(x))-1) >= 0 || (__x) >= 0) ?		\
> +		(((__x) + ((__d) / 2)) / (__d)) :	\
> +		(((__x) - ((__d) / 2)) / (__d));	\
>  }							\

Looks good to me.  The patch causes no change in text size for
kernel/sched/fair.o and drivers/cpuidle/governors/menu.o, so it seems
that the cc trickery is working.

I'll add it to my tree for testing - please merge this via your tree.

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

* Re: [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends
  2012-08-31 19:38 ` Andrew Morton
@ 2012-08-31 21:05   ` Guenter Roeck
  2012-09-01 17:02   ` Jean Delvare
  1 sibling, 0 replies; 9+ messages in thread
From: Guenter Roeck @ 2012-08-31 21:05 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, Pekka Enberg, Ingo Molnar, H. Peter Anvin,
	Jean Delvare, lm-sensors

On Fri, Aug 31, 2012 at 12:38:12PM -0700, Andrew Morton wrote:
> On Fri, 31 Aug 2012 08:02:19 -0700
> Guenter Roeck <linux@roeck-us.net> wrote:
> 
> > DIV_ROUND_CLOSEST returns a bad result for negative dividends:
> > 	DIV_ROUND_CLOSEST(-2, 2) = 0
> > 
> > Most of the time this does not matter. However, in the hardware monitoring
> > subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be
> > negative (such as temperatures).
> > 
> > ...
> >
> > +
> > +/*
> > + * Divide positive or negative dividend by positive divisor and round
> > + * to closest integer. Result is undefined for negative divisors.
> > + */
> >  #define DIV_ROUND_CLOSEST(x, divisor)(			\
> >  {							\
> > -	typeof(divisor) __divisor = divisor;		\
> > -	(((x) + ((__divisor) / 2)) / (__divisor));	\
> > +	typeof(x) __x = x;				\
> > +	typeof(divisor) __d = divisor;			\
> > +	(((typeof(x))-1) >= 0 || (__x) >= 0) ?		\
> > +		(((__x) + ((__d) / 2)) / (__d)) :	\
> > +		(((__x) - ((__d) / 2)) / (__d));	\
> >  }							\
> 
> Looks good to me.  The patch causes no change in text size for
> kernel/sched/fair.o and drivers/cpuidle/governors/menu.o, so it seems
> that the cc trickery is working.
> 
> I'll add it to my tree for testing - please merge this via your tree.
> 
Will do.

Thanks,
Guenter

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

* Re: [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support  negative dividends
  2012-08-31 19:38 ` Andrew Morton
  2012-08-31 21:05   ` Guenter Roeck
@ 2012-09-01 17:02   ` Jean Delvare
  2012-09-02  2:14     ` Guenter Roeck
  1 sibling, 1 reply; 9+ messages in thread
From: Jean Delvare @ 2012-09-01 17:02 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Guenter Roeck, linux-kernel, Pekka Enberg, Ingo Molnar,
	H. Peter Anvin, lm-sensors

Hi Andrew, Guenter,

On Fri, 31 Aug 2012 12:38:12 -0700, Andrew Morton wrote:
> On Fri, 31 Aug 2012 08:02:19 -0700
> Guenter Roeck <linux@roeck-us.net> wrote:
> 
> > DIV_ROUND_CLOSEST returns a bad result for negative dividends:
> > 	DIV_ROUND_CLOSEST(-2, 2) = 0
> > 
> > Most of the time this does not matter. However, in the hardware monitoring
> > subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be
> > negative (such as temperatures).
> > 
> > ...
> >
> > +
> > +/*
> > + * Divide positive or negative dividend by positive divisor and round
> > + * to closest integer. Result is undefined for negative divisors.
> > + */
> >  #define DIV_ROUND_CLOSEST(x, divisor)(			\
> >  {							\
> > -	typeof(divisor) __divisor = divisor;		\
> > -	(((x) + ((__divisor) / 2)) / (__divisor));	\
> > +	typeof(x) __x = x;				\
> > +	typeof(divisor) __d = divisor;			\
> > +	(((typeof(x))-1) >= 0 || (__x) >= 0) ?		\
> > +		(((__x) + ((__d) / 2)) / (__d)) :	\
> > +		(((__x) - ((__d) / 2)) / (__d));	\
> >  }							\
> 
> Looks good to me.

My testing looks good too.

Acked-by: Jean Delvare <khali@linux-fr.org>

> The patch causes no change in text size for
> kernel/sched/fair.o and drivers/cpuidle/governors/menu.o, so it seems
> that the cc trickery is working.

Indeed. I looked for test size increase, and for my config, besides
hwmon, I only spotted the following ones:

drivers/media/rc/mceusb.o
drivers/gpu/drm/i915/intel_pm.o
drivers/tty/serial/pch_uart.o

These don't look like hot paths, so I'd say we don't care. Plus the
intel_pm one can probably be solved by using an unsigned int, I don't
see why/how ia_freq could be negative (negative frequency anyone?) And
for mceusb it can be solved easily by changing "1" to "1U".

For hwmon drivers, we typically only use DIV_ROUND_CLOSEST when the
user changes a setting, this isn't a frequent event. Plus, this is
exactly the case we are fixing here, as temperature limits, and to a
lesser extent voltage limits, can be negative.

> I'll add it to my tree for testing - please merge this via your tree.

-- 
Jean Delvare

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

* Re: [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends
  2012-09-01 17:02   ` Jean Delvare
@ 2012-09-02  2:14     ` Guenter Roeck
  0 siblings, 0 replies; 9+ messages in thread
From: Guenter Roeck @ 2012-09-02  2:14 UTC (permalink / raw)
  To: Jean Delvare
  Cc: Andrew Morton, linux-kernel, Pekka Enberg, Ingo Molnar,
	H. Peter Anvin, lm-sensors

On Sat, Sep 01, 2012 at 07:02:54PM +0200, Jean Delvare wrote:
> Hi Andrew, Guenter,
> 
> On Fri, 31 Aug 2012 12:38:12 -0700, Andrew Morton wrote:
> > On Fri, 31 Aug 2012 08:02:19 -0700
> > Guenter Roeck <linux@roeck-us.net> wrote:
> > 
> > > DIV_ROUND_CLOSEST returns a bad result for negative dividends:
> > > 	DIV_ROUND_CLOSEST(-2, 2) = 0
> > > 
> > > Most of the time this does not matter. However, in the hardware monitoring
> > > subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be
> > > negative (such as temperatures).
> > > 
> > > ...
> > >
> > > +
> > > +/*
> > > + * Divide positive or negative dividend by positive divisor and round
> > > + * to closest integer. Result is undefined for negative divisors.
> > > + */
> > >  #define DIV_ROUND_CLOSEST(x, divisor)(			\
> > >  {							\
> > > -	typeof(divisor) __divisor = divisor;		\
> > > -	(((x) + ((__divisor) / 2)) / (__divisor));	\
> > > +	typeof(x) __x = x;				\
> > > +	typeof(divisor) __d = divisor;			\
> > > +	(((typeof(x))-1) >= 0 || (__x) >= 0) ?		\
> > > +		(((__x) + ((__d) / 2)) / (__d)) :	\
> > > +		(((__x) - ((__d) / 2)) / (__d));	\
> > >  }							\
> > 
> > Looks good to me.
> 
> My testing looks good too.
> 
> Acked-by: Jean Delvare <khali@linux-fr.org>
> 
Thanks a lot!

> > The patch causes no change in text size for
> > kernel/sched/fair.o and drivers/cpuidle/governors/menu.o, so it seems
> > that the cc trickery is working.
> 
> Indeed. I looked for test size increase, and for my config, besides
> hwmon, I only spotted the following ones:
> 
> drivers/media/rc/mceusb.o
> drivers/gpu/drm/i915/intel_pm.o
> drivers/tty/serial/pch_uart.o
> 
> These don't look like hot paths, so I'd say we don't care. Plus the
> intel_pm one can probably be solved by using an unsigned int, I don't
> see why/how ia_freq could be negative (negative frequency anyone?) And
> for mceusb it can be solved easily by changing "1" to "1U".
> 
Yes, it helps a lot that the C trickery optimizes the changes away most of the time.

I'll let the patch rest in -next for a few more days before I send it to Linus.

Guenter

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

* Re: [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends
  2012-08-31 15:02 [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends Guenter Roeck
  2012-08-31 19:38 ` Andrew Morton
@ 2012-09-09 14:57 ` Geert Uytterhoeven
  2012-09-09 16:17   ` Guenter Roeck
  1 sibling, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2012-09-09 14:57 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel, Andrew Morton, Pekka Enberg, Ingo Molnar,
	H. Peter Anvin, Jean Delvare, lm-sensors

On Fri, Aug 31, 2012 at 5:02 PM, Guenter Roeck <linux@roeck-us.net> wrote:
> DIV_ROUND_CLOSEST returns a bad result for negative dividends:
>         DIV_ROUND_CLOSEST(-2, 2) = 0
>
> Most of the time this does not matter. However, in the hardware monitoring
> subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be
> negative (such as temperatures).

This seems to cause 3 new warnings in my m68k builds of v3.6-rc5:

drivers/hwmon/mcp3021.c:76: warning: comparison is always true due to
limited range of data type
drivers/ide/ide-cd.c:1158: warning: comparison is always true due to
limited range of data type
drivers/ide/ide-cd.c:1159: warning: comparison is always true due to
limited range of data type

$ m68k-linux-gnu-gcc -v
Using built-in specs.
Target: m68k-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++
--prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/m68k-linux-gnu/include/c++/4.1.2
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --disable-libssp --disable-werror
--enable-checking=release --program-prefix=m68k-linux-gnu-
--includedir=/usr/m68k-linux-gnu/include --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=m68k-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends
  2012-09-09 14:57 ` Geert Uytterhoeven
@ 2012-09-09 16:17   ` Guenter Roeck
  2012-09-09 20:38     ` Geert Uytterhoeven
  0 siblings, 1 reply; 9+ messages in thread
From: Guenter Roeck @ 2012-09-09 16:17 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-kernel, Andrew Morton, Pekka Enberg, Ingo Molnar,
	H. Peter Anvin, Jean Delvare, lm-sensors

On Sun, Sep 09, 2012 at 04:57:34PM +0200, Geert Uytterhoeven wrote:
> On Fri, Aug 31, 2012 at 5:02 PM, Guenter Roeck <linux@roeck-us.net> wrote:
> > DIV_ROUND_CLOSEST returns a bad result for negative dividends:
> >         DIV_ROUND_CLOSEST(-2, 2) = 0
> >
> > Most of the time this does not matter. However, in the hardware monitoring
> > subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be
> > negative (such as temperatures).
> 
> This seems to cause 3 new warnings in my m68k builds of v3.6-rc5:
> 
> drivers/hwmon/mcp3021.c:76: warning: comparison is always true due to
> limited range of data type
> drivers/ide/ide-cd.c:1158: warning: comparison is always true due to
> limited range of data type
> drivers/ide/ide-cd.c:1159: warning: comparison is always true due to
> limited range of data type
> 
> $ m68k-linux-gnu-gcc -v
> Using built-in specs.
> Target: m68k-linux-gnu
> Configured with: ../src/configure -v --enable-languages=c,c++
> --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
> --without-included-gettext --enable-threads=posix --enable-nls
> --with-gxx-include-dir=/usr/m68k-linux-gnu/include/c++/4.1.2
> --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
> --enable-libstdcxx-debug --disable-libssp --disable-werror
> --enable-checking=release --program-prefix=m68k-linux-gnu-
> --includedir=/usr/m68k-linux-gnu/include --build=x86_64-linux-gnu
> --host=x86_64-linux-gnu --target=m68k-linux-gnu
> Thread model: posix
> gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)
> 
Hi Gert,

The "always true" condition is on purpose to cause the compiler to optimize the
expression away. I don't see the warnings myself, on none of the targets I am
building (x86, ppc, arm, mips), but then I am using much more recent compiler
versions. Odd is that you only see the warnings on "u16" and not elsewhere.

I don't immediately see the warnings with a more recent m68k compiler (4.6.3),
nor with any other target (x86, ppc, arm, mips) in my nightly builds.
Can you send me your configuration ?
Also, do you know where I can find the Ubuntu/Debian package for your compiler
version, by any chance ?

Thanks,
Guenter

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

* Re: [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends
  2012-09-09 16:17   ` Guenter Roeck
@ 2012-09-09 20:38     ` Geert Uytterhoeven
  2012-09-09 21:30       ` Guenter Roeck
  0 siblings, 1 reply; 9+ messages in thread
From: Geert Uytterhoeven @ 2012-09-09 20:38 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel, Andrew Morton, Pekka Enberg, Ingo Molnar,
	H. Peter Anvin, Jean Delvare, lm-sensors

Hi Günter,

On Sun, Sep 9, 2012 at 6:17 PM, Guenter Roeck <linux@roeck-us.net> wrote:
> On Sun, Sep 09, 2012 at 04:57:34PM +0200, Geert Uytterhoeven wrote:
>> On Fri, Aug 31, 2012 at 5:02 PM, Guenter Roeck <linux@roeck-us.net> wrote:
>> > DIV_ROUND_CLOSEST returns a bad result for negative dividends:
>> >         DIV_ROUND_CLOSEST(-2, 2) = 0
>> >
>> > Most of the time this does not matter. However, in the hardware monitoring
>> > subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be
>> > negative (such as temperatures).
>>
>> This seems to cause 3 new warnings in my m68k builds of v3.6-rc5:
>>
>> drivers/hwmon/mcp3021.c:76: warning: comparison is always true due to
>> limited range of data type
>> drivers/ide/ide-cd.c:1158: warning: comparison is always true due to
>> limited range of data type
>> drivers/ide/ide-cd.c:1159: warning: comparison is always true due to
>> limited range of data type
>>
>> $ m68k-linux-gnu-gcc -v
>> Using built-in specs.
>> Target: m68k-linux-gnu
>> Configured with: ../src/configure -v --enable-languages=c,c++
>> --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
>> --without-included-gettext --enable-threads=posix --enable-nls
>> --with-gxx-include-dir=/usr/m68k-linux-gnu/include/c++/4.1.2
>> --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
>> --enable-libstdcxx-debug --disable-libssp --disable-werror
>> --enable-checking=release --program-prefix=m68k-linux-gnu-
>> --includedir=/usr/m68k-linux-gnu/include --build=x86_64-linux-gnu
>> --host=x86_64-linux-gnu --target=m68k-linux-gnu
>> Thread model: posix
>> gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)
>>
> The "always true" condition is on purpose to cause the compiler to optimize the
> expression away. I don't see the warnings myself, on none of the targets I am
> building (x86, ppc, arm, mips), but then I am using much more recent compiler
> versions. Odd is that you only see the warnings on "u16" and not elsewhere.
>
> I don't immediately see the warnings with a more recent m68k compiler (4.6.3),
> nor with any other target (x86, ppc, arm, mips) in my nightly builds.

I also don't see it in any of the linux-next builds of v3.6-rc5. So
probably it's just
a gcc 4.1.2 issue...

> Can you send me your configuration ?

The ide-cd one shows up in any config that enables ide-cd, incl. defconfig and
allmodconfig.
The mcp3021 one I only see in allmodconfig.

> Also, do you know where I can find the Ubuntu/Debian package for your compiler
> version, by any chance ?

It's not from an official binary package. I built the cross-compiler
from the then
current gcc 4.1.1-21 sources in Ubuntu.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends
  2012-09-09 20:38     ` Geert Uytterhoeven
@ 2012-09-09 21:30       ` Guenter Roeck
  0 siblings, 0 replies; 9+ messages in thread
From: Guenter Roeck @ 2012-09-09 21:30 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-kernel, Andrew Morton, Pekka Enberg, Ingo Molnar,
	H. Peter Anvin, Jean Delvare, lm-sensors

On Sun, Sep 09, 2012 at 10:38:41PM +0200, Geert Uytterhoeven wrote:
> Hi Günter,
> 
> On Sun, Sep 9, 2012 at 6:17 PM, Guenter Roeck <linux@roeck-us.net> wrote:
> > On Sun, Sep 09, 2012 at 04:57:34PM +0200, Geert Uytterhoeven wrote:
> >> On Fri, Aug 31, 2012 at 5:02 PM, Guenter Roeck <linux@roeck-us.net> wrote:
> >> > DIV_ROUND_CLOSEST returns a bad result for negative dividends:
> >> >         DIV_ROUND_CLOSEST(-2, 2) = 0
> >> >
> >> > Most of the time this does not matter. However, in the hardware monitoring
> >> > subsystem, DIV_ROUND_CLOSEST is sometimes used on integers which can be
> >> > negative (such as temperatures).
> >>
> >> This seems to cause 3 new warnings in my m68k builds of v3.6-rc5:
> >>
> >> drivers/hwmon/mcp3021.c:76: warning: comparison is always true due to
> >> limited range of data type
> >> drivers/ide/ide-cd.c:1158: warning: comparison is always true due to
> >> limited range of data type
> >> drivers/ide/ide-cd.c:1159: warning: comparison is always true due to
> >> limited range of data type
> >>
> >> $ m68k-linux-gnu-gcc -v
> >> Using built-in specs.
> >> Target: m68k-linux-gnu
> >> Configured with: ../src/configure -v --enable-languages=c,c++
> >> --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib
> >> --without-included-gettext --enable-threads=posix --enable-nls
> >> --with-gxx-include-dir=/usr/m68k-linux-gnu/include/c++/4.1.2
> >> --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
> >> --enable-libstdcxx-debug --disable-libssp --disable-werror
> >> --enable-checking=release --program-prefix=m68k-linux-gnu-
> >> --includedir=/usr/m68k-linux-gnu/include --build=x86_64-linux-gnu
> >> --host=x86_64-linux-gnu --target=m68k-linux-gnu
> >> Thread model: posix
> >> gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)
> >>
> > The "always true" condition is on purpose to cause the compiler to optimize the
> > expression away. I don't see the warnings myself, on none of the targets I am
> > building (x86, ppc, arm, mips), but then I am using much more recent compiler
> > versions. Odd is that you only see the warnings on "u16" and not elsewhere.
> >
> > I don't immediately see the warnings with a more recent m68k compiler (4.6.3),
> > nor with any other target (x86, ppc, arm, mips) in my nightly builds.
> 
> I also don't see it in any of the linux-next builds of v3.6-rc5. So
> probably it's just
> a gcc 4.1.2 issue...
> 
> > Can you send me your configuration ?
> 
> The ide-cd one shows up in any config that enables ide-cd, incl. defconfig and
> allmodconfig.
> The mcp3021 one I only see in allmodconfig.
> 
I tried both and did not see the problem. I agree, it does look like a compiler
version problem.


> > Also, do you know where I can find the Ubuntu/Debian package for your compiler
> > version, by any chance ?
> 
> It's not from an official binary package. I built the cross-compiler
> from the then
> current gcc 4.1.1-21 sources in Ubuntu.
> 
Ok. 

Just in case you are interested, I installed the m68k cross-compiler from
	deb http://www.freewrt.org/~tg/debs68k/ cross main

For my other targets, I use Yocto builds.

I think I'll let this go as false positive for now, unless there are problems
with more recent compilers.

Thanks,
Guenter

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

end of thread, other threads:[~2012-09-09 21:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-31 15:02 [PATCH v4] linux/kernel.h: Fix DIV_ROUND_CLOSEST to support negative dividends Guenter Roeck
2012-08-31 19:38 ` Andrew Morton
2012-08-31 21:05   ` Guenter Roeck
2012-09-01 17:02   ` Jean Delvare
2012-09-02  2:14     ` Guenter Roeck
2012-09-09 14:57 ` Geert Uytterhoeven
2012-09-09 16:17   ` Guenter Roeck
2012-09-09 20:38     ` Geert Uytterhoeven
2012-09-09 21:30       ` Guenter Roeck

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).