diff mbox

Net: mac802154: comparing issue by type cast, finding by EXTRA_CFLAGS=-W

Message ID 5174DB87.3010908@asianux.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Chen Gang April 22, 2013, 6:41 a.m. UTC
need change ~(u8)0 to 0xff,
  or in mac802154_wpan_xmit(), "u8 chan" will never == MAC802154_CHAN_NONE

  find it by "make EXTRA_CFLAGS=-W"
    net/mac802154/wpan.c:325:2: warning: comparison is always false
    due to limited range of data type [-Wtype-limits]

  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 files changed, 1 insertions(+), 1 deletions(-)

Comments

Sergei Shtylyov April 22, 2013, 2:09 p.m. UTC | #1
Hello.

On 22-04-2013 10:41, Chen Gang wrote:

>    need change ~(u8)0 to 0xff,
>    or in mac802154_wpan_xmit(), "u8 chan" will never == MAC802154_CHAN_NONE

>    find it by "make EXTRA_CFLAGS=-W"
>      net/mac802154/wpan.c:325:2: warning: comparison is always false
>      due to limited range of data type [-Wtype-limits]

>    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 files changed, 1 insertions(+), 1 deletions(-)

> diff --git a/net/mac802154/mac802154.h b/net/mac802154/mac802154.h
> index 5c9e021..c59309f 100644
> --- a/net/mac802154/mac802154.h
> +++ b/net/mac802154/mac802154.h
> @@ -88,7 +88,7 @@ struct mac802154_sub_if_data {
>
>   #define mac802154_to_priv(_hw)	container_of(_hw, struct mac802154_priv, hw)
>
> -#define MAC802154_CHAN_NONE		(~(u8)0) /* No channel is assigned */
> +#define MAC802154_CHAN_NONE		(0xff) /* No channel is assigned */

    () not needed now.

WBR, Sergei

--
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 April 23, 2013, 1:11 a.m. UTC | #2
On 2013年04月22日 22:09, Sergei Shtylyov wrote:
> 
>> Signed-off-by: Chen Gang <gang.chen@asianux.com>
>> ---
>>   net/mac802154/mac802154.h |    2 +-
>>   1 files changed, 1 insertions(+), 1 deletions(-)
> 
>> diff --git a/net/mac802154/mac802154.h b/net/mac802154/mac802154.h
>> index 5c9e021..c59309f 100644
>> --- a/net/mac802154/mac802154.h
>> +++ b/net/mac802154/mac802154.h
>> @@ -88,7 +88,7 @@ struct mac802154_sub_if_data {
>>
>>   #define mac802154_to_priv(_hw)    container_of(_hw, struct
>> mac802154_priv, hw)
>>
>> -#define MAC802154_CHAN_NONE        (~(u8)0) /* No channel is assigned */
>> +#define MAC802154_CHAN_NONE        (0xff) /* No channel is assigned */
> 
>    () not needed now.
> 
> WBR, Sergei
> 
> 

  ok, thanks.  I will send patch v2
diff mbox

Patch

diff --git a/net/mac802154/mac802154.h b/net/mac802154/mac802154.h
index 5c9e021..c59309f 100644
--- a/net/mac802154/mac802154.h
+++ b/net/mac802154/mac802154.h
@@ -88,7 +88,7 @@  struct mac802154_sub_if_data {
 
 #define mac802154_to_priv(_hw)	container_of(_hw, struct mac802154_priv, hw)
 
-#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;