[PATCH] compilation warning is caused when using hweight_longWarning message is 'include/linux/bitops.h: In function 'hweight_long':include/linux/bitops.h:49: warning: signed and unsigned type inThe reason is that the default return value of this macro is signed.

From: Namjae Jeon
Date: Tue Jun 21 2011 - 01:39:03 EST


Signed-off-by: Namjae Jeon <linkinjeon@xxxxxxxxx>
---
include/asm-generic/bitops/const_hweight.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/asm-generic/bitops/const_hweight.h
b/include/asm-generic/bitops/const_hweight.h
index fa2a50b..d91b1aa 100644
--- a/include/asm-generic/bitops/const_hweight.h
+++ b/include/asm-generic/bitops/const_hweight.h
@@ -4,7 +4,7 @@
/*
* Compile time versions of __arch_hweightN()
*/
-#define __const_hweight8(w) \
+#define __const_hweight8(w) (unsigned long) \
( (!!((w) & (1ULL << 0))) + \
(!!((w) & (1ULL << 1))) + \
(!!((w) & (1ULL << 2))) + \
--
1.7.4-rc2



--------------------------------------------------------------------------------------------------------------------------------------
2011/6/20 Arnd Bergmann <arnd@xxxxxxxx>:
> On Monday 20 June 2011, NamJae Jeon wrote:
>> I found compile warning while compiling module when using -Wsign-compare option.
>>
>> include/linux/bitops.h: In function 'hweight_long':
>> include/linux/bitops.h:49: warning: signed and unsigned type in
>> conditional expression
>>
>> I found the reason of this problem that the default return value of
>> the below macro is signed.
>>
>> #define __const_hweight8(w)        \
>>       ( (!!((w) & (1ULL << 0))) +       \
>>         (!!((w) & (1ULL << 1))) +       \
>>         (!!((w) & (1ULL << 2))) +       \
>>         (!!((w) & (1ULL << 3))) +       \
>>         (!!((w) & (1ULL << 4))) +       \
>>         (!!((w) & (1ULL << 5))) +       \
>>         (!!((w) & (1ULL << 6))) +       \
>>         (!!((w) & (1ULL << 7))) )
>>
>> So, I try to add (unsigned long) in __const_hweight8 like this.
>>
>> #define __const_hweight8(w)     (unsigned long )        \
>>       ( (!!((w) & (1ULL << 0))) +       \
>>         (!!((w) & (1ULL << 1))) +       \
>>         (!!((w) & (1ULL << 2))) +       \
>>         (!!((w) & (1ULL << 3))) +       \
>>         (!!((w) & (1ULL << 4))) +       \
>>         (!!((w) & (1ULL << 5))) +       \
>>         (!!((w) & (1ULL << 6))) +       \
>>         (!!((w) & (1ULL << 7))) )
>>
>> so, I can't see compile warning after fixing it, Would you plz check this ?
>
> Yes, this looks correct to me. Could you send the change as a proper patch
> with your Signed-off-by:?
>
>        Arnd
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/