Message ID | 5178FA0D.8060009@asianux.com |
---|---|
State | Superseded, archived |
Delegated to: | David Miller |
Headers | show |
On 04/25/2013 11:40 AM, Chen Gang wrote: > Need change ~(u8)0 to 0xff, or in mac802154_wpan_xmit(), "u8 chan" > will never == MAC802154_CHAN_NONE. > > The related warning: > net/mac802154/wpan.c:325:2: warning: comparison is always false > due to limited range of data type [-Wtype-limits] Hm, do you really need to include this huge pile of code below into the commit message? Couldn't you make the commit message simpler resp. more compact, e.g.: Change MAC802154_CHAN_NONE from ~(u8)0 to 0xff, otherwise 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. .... something like that maybe? > The related unit test: > cc -Wall -O2 -o test test.c > ./test > will output 'different' > > (after use '0xff' instead of '~(u8)0', it will output 'equal') > > -----------------------test code begin-------------------------------- > > #include <stdio.h> > > typedef unsigned char u8; > > int main() > { > u8 uc = 0xff; > > if (uc == ~(u8)0) > printf("\nequal\n"); > else > printf("\ndifferent\n"); > > return 0; > } > > -----------------------test code end---------------------------------- > > > Signed-off-by: Chen Gang <gang.chen@asianux.com> > --- > net/mac802154/mac802154.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > 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; > -- 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
On 2013年04月25日 17:59, Daniel Borkmann wrote: > Change MAC802154_CHAN_NONE from ~(u8)0 to 0xff, otherwise 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. > > ... something like that maybe? That sounds good !! I prefer to send patch v5 for that. :-)
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;
Need change ~(u8)0 to 0xff, or in mac802154_wpan_xmit(), "u8 chan" will never == MAC802154_CHAN_NONE. The related warning: net/mac802154/wpan.c:325:2: warning: comparison is always false due to limited range of data type [-Wtype-limits] The related unit test: cc -Wall -O2 -o test test.c ./test will output 'different' (after use '0xff' instead of '~(u8)0', it will output 'equal') -----------------------test code begin-------------------------------- #include <stdio.h> typedef unsigned char u8; int main() { u8 uc = 0xff; if (uc == ~(u8)0) printf("\nequal\n"); else printf("\ndifferent\n"); return 0; } -----------------------test code end---------------------------------- Signed-off-by: Chen Gang <gang.chen@asianux.com> --- net/mac802154/mac802154.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)