Patchwork [v5] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

login
register
mail settings
Submitter Chen Gang
Date April 25, 2013, 10:49 a.m.
Message ID <51790A53.8040107@asianux.com>
Download mbox | patch
Permalink /patch/239488/
State Accepted
Delegated to: David Miller
Headers show

Comments

Chen Gang - April 25, 2013, 10:49 a.m.
Change MAC802154_CHAN_NONE from ~(u8)0 to 0xff, or the comparison in
mac802154_wpan_xmit() for ``chan == MAC802154_CHAN_NONE'' will not
succeed.

This bug can be boiled down to ``u8 foo = 0xff; if (foo == ~(u8)0)
[...] else [...]'' where the condition will always take the else
branch. 

Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 net/mac802154/mac802154.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
David Miller - April 29, 2013, 4:29 p.m.
From: Chen Gang <gang.chen@asianux.com>
Date: Thu, 25 Apr 2013 18:49:55 +0800

> 
> Change MAC802154_CHAN_NONE from ~(u8)0 to 0xff, or the comparison in
> mac802154_wpan_xmit() for ``chan == MAC802154_CHAN_NONE'' will not
> succeed.
> 
> This bug can be boiled down to ``u8 foo = 0xff; if (foo == ~(u8)0)
> [...] else [...]'' where the condition will always take the else
> branch. 
> 
> Signed-off-by: Chen Gang <gang.chen@asianux.com>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chen Gang - May 2, 2013, 1:11 a.m.
On 2013年04月30日 00:29, David Miller wrote:
> From: Chen Gang <gang.chen@asianux.com>
> Date: Thu, 25 Apr 2013 18:49:55 +0800
> 
>>
>> Change MAC802154_CHAN_NONE from ~(u8)0 to 0xff, or the comparison in
>> mac802154_wpan_xmit() for ``chan == MAC802154_CHAN_NONE'' will not
>> succeed.
>>
>> This bug can be boiled down to ``u8 foo = 0xff; if (foo == ~(u8)0)
>> [...] else [...]'' where the condition will always take the else
>> branch. 
>>
>> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> 
> Applied, thanks.
> 
> 

Thank you, too, and also thank the related members who provide your
suggestions to this patch.

Patch

diff --git a/net/mac802154/mac802154.h b/net/mac802154/mac802154.h
index a4dcaf1..703c121 100644
--- a/net/mac802154/mac802154.h
+++ b/net/mac802154/mac802154.h
@@ -90,7 +90,7 @@  struct mac802154_sub_if_data {
 
 #define MAC802154_MAX_XMIT_ATTEMPTS	3
 
-#define MAC802154_CHAN_NONE		(~(u8)0) /* No channel is assigned */
+#define MAC802154_CHAN_NONE		0xff /* No channel is assigned */
 
 extern struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced;
 extern struct ieee802154_mlme_ops mac802154_mlme_wpan;