netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Net: mac802154: comparing issue by type cast, finding by EXTRA_CFLAGS=-W
@ 2013-04-22  6:41 Chen Gang
  2013-04-22 14:09 ` Sergei Shtylyov
  0 siblings, 1 reply; 18+ messages in thread
From: Chen Gang @ 2013-04-22  6:41 UTC (permalink / raw)
  To: alex.bluesman.smirnov, dbaryshkov
  Cc: David Miller, linux-zigbee-devel, netdev


  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 */
 
 extern struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced;
 extern struct ieee802154_mlme_ops mac802154_mlme_wpan;
-- 
1.7.7.6

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

* Re: [PATCH] Net: mac802154: comparing issue by type cast, finding by EXTRA_CFLAGS=-W
  2013-04-22  6:41 [PATCH] Net: mac802154: comparing issue by type cast, finding by EXTRA_CFLAGS=-W Chen Gang
@ 2013-04-22 14:09 ` Sergei Shtylyov
  2013-04-23  1:11   ` Chen Gang
  0 siblings, 1 reply; 18+ messages in thread
From: Sergei Shtylyov @ 2013-04-22 14:09 UTC (permalink / raw)
  To: Chen Gang
  Cc: alex.bluesman.smirnov, dbaryshkov, David Miller,
	linux-zigbee-devel, netdev

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

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

* Re: [PATCH] Net: mac802154: comparing issue by type cast, finding by EXTRA_CFLAGS=-W
  2013-04-22 14:09 ` Sergei Shtylyov
@ 2013-04-23  1:11   ` Chen Gang
  2013-04-23  2:54     ` [PATCH v2] Net: mac802154: comparision issue of " Chen Gang
  0 siblings, 1 reply; 18+ messages in thread
From: Chen Gang @ 2013-04-23  1:11 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: alex.bluesman.smirnov, dbaryshkov, David Miller,
	linux-zigbee-devel, netdev

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

-- 
Chen Gang

Asianux Corporation

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

* [PATCH v2] Net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-23  1:11   ` Chen Gang
@ 2013-04-23  2:54     ` Chen Gang
  2013-04-23 11:22       ` Chen Gang
  2013-04-23 11:24       ` [PATCH v3] net: " Chen Gang
  0 siblings, 2 replies; 18+ messages in thread
From: Chen Gang @ 2013-04-23  2:54 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: alex.bluesman.smirnov, dbaryshkov, David Miller,
	linux-zigbee-devel, netdev


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]

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..d48422e 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;
-- 
1.7.7.6

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

* Re: [PATCH v2] Net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-23  2:54     ` [PATCH v2] Net: mac802154: comparision issue of " Chen Gang
@ 2013-04-23 11:22       ` Chen Gang
  2013-04-23 11:24       ` [PATCH v3] net: " Chen Gang
  1 sibling, 0 replies; 18+ messages in thread
From: Chen Gang @ 2013-04-23 11:22 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: alex.bluesman.smirnov, dbaryshkov, David Miller,
	linux-zigbee-devel, netdev


I will send patch v3 for properly capitalizing my comments' sentences
and subject.

On 2013年04月23日 10:54, 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]
> 
> 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..d48422e 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;
> 


-- 
Chen Gang

Asianux Corporation

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

* [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-23  2:54     ` [PATCH v2] Net: mac802154: comparision issue of " Chen Gang
  2013-04-23 11:22       ` Chen Gang
@ 2013-04-23 11:24       ` Chen Gang
  2013-04-25  8:10         ` David Miller
  1 sibling, 1 reply; 18+ messages in thread
From: Chen Gang @ 2013-04-23 11:24 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: alex.bluesman.smirnov, dbaryshkov, David Miller,
	linux-zigbee-devel, netdev


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

diff --git a/net/mac802154/mac802154.h b/net/mac802154/mac802154.h
index 5c9e021..d48422e 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;
-- 
1.7.7.6

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

* Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-23 11:24       ` [PATCH v3] net: " Chen Gang
@ 2013-04-25  8:10         ` David Miller
  2013-04-25  8:43           ` Chen Gang
  0 siblings, 1 reply; 18+ messages in thread
From: David Miller @ 2013-04-25  8:10 UTC (permalink / raw)
  To: gang.chen
  Cc: sergei.shtylyov, alex.bluesman.smirnov, dbaryshkov,
	linux-zigbee-devel, netdev

From: Chen Gang <gang.chen@asianux.com>
Date: Tue, 23 Apr 2013 19:24:36 +0800

> 
> 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')
 ...
> Signed-off-by: Chen Gang <gang.chen@asianux.com>

This change belong in the 'net' tree, but your patch won't apply
cleanly there as this part of the header file looks slightly
different there.

Please respin your patch against 'net' and resubmit, thank you.

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

* Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-25  8:10         ` David Miller
@ 2013-04-25  8:43           ` Chen Gang
  2013-04-25  9:01             ` David Miller
       [not found]             ` <5178ECA2.6020402-bOixZGp5f+dBDgjK7y7TUQ@public.gmane.org>
  0 siblings, 2 replies; 18+ messages in thread
From: Chen Gang @ 2013-04-25  8:43 UTC (permalink / raw)
  To: David Miller
  Cc: sergei.shtylyov, alex.bluesman.smirnov, dbaryshkov,
	linux-zigbee-devel, netdev

On 2013年04月25日 16:10, David Miller wrote:
> From: Chen Gang <gang.chen@asianux.com>
> Date: Tue, 23 Apr 2013 19:24:36 +0800
> 
>> > 
>> > 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')
>  ...
>> > Signed-off-by: Chen Gang <gang.chen@asianux.com>
> This change belong in the 'net' tree, but your patch won't apply
> cleanly there as this part of the header file looks slightly
> different there.
> 
> Please respin your patch against 'net' and resubmit, thank you.
> 

Excuse me, my English is not quite well, I guess your meaning is: send
patch v4, and change the subject to "[PATCH v4] mac802154: comparision
issue of type cast, finding by EXTRA_CFLAGS=-W".

Is it correct ?

(the change is for net/mac802154/mac802154.h, and exist in v3.9-rc8)

Thanks.

-- 
Chen Gang

Asianux Corporation

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

* Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-25  8:43           ` Chen Gang
@ 2013-04-25  9:01             ` David Miller
  2013-04-25  9:09               ` Chen Gang
       [not found]             ` <5178ECA2.6020402-bOixZGp5f+dBDgjK7y7TUQ@public.gmane.org>
  1 sibling, 1 reply; 18+ messages in thread
From: David Miller @ 2013-04-25  9:01 UTC (permalink / raw)
  To: gang.chen
  Cc: sergei.shtylyov, alex.bluesman.smirnov, dbaryshkov,
	linux-zigbee-devel, netdev

From: Chen Gang <gang.chen@asianux.com>
Date: Thu, 25 Apr 2013 16:43:14 +0800

> (the change is for net/mac802154/mac802154.h, and exist in v3.9-rc8)

It exist, but your patch doesn't apply cleanly there, it only applies
cleanly to the -next tree, because other changes have happend to that
file in -next.

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

* Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
       [not found]             ` <5178ECA2.6020402-bOixZGp5f+dBDgjK7y7TUQ@public.gmane.org>
@ 2013-04-25  9:02               ` Christophe Aeschlimann
  2013-04-25  9:06                 ` Chen Gang
  2013-04-25  9:40                 ` [PATCH v4] " Chen Gang
  0 siblings, 2 replies; 18+ messages in thread
From: Christophe Aeschlimann @ 2013-04-25  9:02 UTC (permalink / raw)
  To: Chen Gang
  Cc: sergei.shtylyov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8,
	netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-zigbee-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	David Miller

Hi Chen,

Le 25.04.2013 10:43, Chen Gang a écrit :
> On 2013年04月25日 16:10, David Miller wrote:
>>
>> Please respin your patch against 'net' and resubmit, thank you.
>>
> 
> Excuse me, my English is not quite well, I guess your meaning is: send
> patch v4, and change the subject to "[PATCH v4] mac802154: comparision
> issue of type cast, finding by EXTRA_CFLAGS=-W".
> 
> Is it correct ?
> 
> (the change is for net/mac802154/mac802154.h, and exist in v3.9-rc8)
> 
> Thanks.

He means you should clone :

git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git

And apply your change to that tree and re-submit. (mac802154.h is
slightly different in that tree).

Best regards,

-- 
Christophe Aeschlimann

Embedded Software Engineer & IT Manager
ACN Advanced Communications Networks S.A.
2000 - Neuchâtel, Switzerland
Tel. +41 32 724 74 31

------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel

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

* Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-25  9:02               ` Christophe Aeschlimann
@ 2013-04-25  9:06                 ` Chen Gang
  2013-04-25  9:40                 ` [PATCH v4] " Chen Gang
  1 sibling, 0 replies; 18+ messages in thread
From: Chen Gang @ 2013-04-25  9:06 UTC (permalink / raw)
  To: Christophe Aeschlimann
  Cc: David Miller, sergei.shtylyov, alex.bluesman.smirnov, dbaryshkov,
	linux-zigbee-devel, netdev

On 2013年04月25日 17:02, Christophe Aeschlimann wrote:
> Hi Chen,
> 
> Le 25.04.2013 10:43, Chen Gang a écrit :
>> > On 2013年04月25日 16:10, David Miller wrote:
>>> >>
>>> >> Please respin your patch against 'net' and resubmit, thank you.
>>> >>
>> > 
>> > Excuse me, my English is not quite well, I guess your meaning is: send
>> > patch v4, and change the subject to "[PATCH v4] mac802154: comparision
>> > issue of type cast, finding by EXTRA_CFLAGS=-W".
>> > 
>> > Is it correct ?
>> > 
>> > (the change is for net/mac802154/mac802154.h, and exist in v3.9-rc8)
>> > 
>> > Thanks.
> He means you should clone :
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git
> 
> And apply your change to that tree and re-submit. (mac802154.h is
> slightly different in that tree).
> 

OK, thank you very much, I will follow.

-- 
Chen Gang

Asianux Corporation

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

* Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-25  9:01             ` David Miller
@ 2013-04-25  9:09               ` Chen Gang
  0 siblings, 0 replies; 18+ messages in thread
From: Chen Gang @ 2013-04-25  9:09 UTC (permalink / raw)
  To: David Miller
  Cc: sergei.shtylyov, alex.bluesman.smirnov, dbaryshkov,
	linux-zigbee-devel, netdev

On 2013年04月25日 17:01, David Miller wrote:
> From: Chen Gang <gang.chen@asianux.com>
> Date: Thu, 25 Apr 2013 16:43:14 +0800
> 
>> > (the change is for net/mac802154/mac802154.h, and exist in v3.9-rc8)
> It exist, but your patch doesn't apply cleanly there, it only applies
> cleanly to the -next tree, because other changes have happend to that
> file in -next.
> 
> 

OK, thanks. I will send patch v4 (still use the current subject and
comments)

-- 
Chen Gang

Asianux Corporation

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

* Re: [PATCH v4] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-25  9:02               ` Christophe Aeschlimann
  2013-04-25  9:06                 ` Chen Gang
@ 2013-04-25  9:40                 ` Chen Gang
  2013-04-25  9:59                   ` Daniel Borkmann
  1 sibling, 1 reply; 18+ messages in thread
From: Chen Gang @ 2013-04-25  9:40 UTC (permalink / raw)
  To: David Miller
  Cc: Christophe Aeschlimann, sergei.shtylyov, alex.bluesman.smirnov,
	dbaryshkov, linux-zigbee-devel, netdev


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

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;
-- 
1.7.11.7

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

* Re: [PATCH v4] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-25  9:40                 ` [PATCH v4] " Chen Gang
@ 2013-04-25  9:59                   ` Daniel Borkmann
  2013-04-25 10:44                     ` Chen Gang
  2013-04-25 10:49                     ` [PATCH v5] " Chen Gang
  0 siblings, 2 replies; 18+ messages in thread
From: Daniel Borkmann @ 2013-04-25  9:59 UTC (permalink / raw)
  To: Chen Gang
  Cc: David Miller, Christophe Aeschlimann, sergei.shtylyov,
	alex.bluesman.smirnov, dbaryshkov, linux-zigbee-devel, netdev

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;
>

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

* Re: [PATCH v4] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-25  9:59                   ` Daniel Borkmann
@ 2013-04-25 10:44                     ` Chen Gang
  2013-04-25 10:49                     ` [PATCH v5] " Chen Gang
  1 sibling, 0 replies; 18+ messages in thread
From: Chen Gang @ 2013-04-25 10:44 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: David Miller, Christophe Aeschlimann, sergei.shtylyov,
	alex.bluesman.smirnov, dbaryshkov, linux-zigbee-devel, netdev

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.

:-)

-- 
Chen Gang

Asianux Corporation

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

* [PATCH v5] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-25  9:59                   ` Daniel Borkmann
  2013-04-25 10:44                     ` Chen Gang
@ 2013-04-25 10:49                     ` Chen Gang
  2013-04-29 16:29                       ` David Miller
  1 sibling, 1 reply; 18+ messages in thread
From: Chen Gang @ 2013-04-25 10:49 UTC (permalink / raw)
  To: David Miller
  Cc: Daniel Borkmann, Christophe Aeschlimann, sergei.shtylyov,
	alex.bluesman.smirnov, dbaryshkov, linux-zigbee-devel, netdev


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

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;
-- 
1.7.11.7

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

* Re: [PATCH v5] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-25 10:49                     ` [PATCH v5] " Chen Gang
@ 2013-04-29 16:29                       ` David Miller
  2013-05-02  1:11                         ` Chen Gang
  0 siblings, 1 reply; 18+ messages in thread
From: David Miller @ 2013-04-29 16:29 UTC (permalink / raw)
  To: gang.chen
  Cc: dborkman, c.aeschlimann, sergei.shtylyov, alex.bluesman.smirnov,
	dbaryshkov, linux-zigbee-devel, netdev

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.

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

* Re: [PATCH v5] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
  2013-04-29 16:29                       ` David Miller
@ 2013-05-02  1:11                         ` Chen Gang
  0 siblings, 0 replies; 18+ messages in thread
From: Chen Gang @ 2013-05-02  1:11 UTC (permalink / raw)
  To: David Miller
  Cc: dborkman, c.aeschlimann, sergei.shtylyov, alex.bluesman.smirnov,
	dbaryshkov, linux-zigbee-devel, netdev

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.

-- 
Chen Gang

Asianux Corporation

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

end of thread, other threads:[~2013-05-02  1:12 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-22  6:41 [PATCH] Net: mac802154: comparing issue by type cast, finding by EXTRA_CFLAGS=-W Chen Gang
2013-04-22 14:09 ` Sergei Shtylyov
2013-04-23  1:11   ` Chen Gang
2013-04-23  2:54     ` [PATCH v2] Net: mac802154: comparision issue of " Chen Gang
2013-04-23 11:22       ` Chen Gang
2013-04-23 11:24       ` [PATCH v3] net: " Chen Gang
2013-04-25  8:10         ` David Miller
2013-04-25  8:43           ` Chen Gang
2013-04-25  9:01             ` David Miller
2013-04-25  9:09               ` Chen Gang
     [not found]             ` <5178ECA2.6020402-bOixZGp5f+dBDgjK7y7TUQ@public.gmane.org>
2013-04-25  9:02               ` Christophe Aeschlimann
2013-04-25  9:06                 ` Chen Gang
2013-04-25  9:40                 ` [PATCH v4] " Chen Gang
2013-04-25  9:59                   ` Daniel Borkmann
2013-04-25 10:44                     ` Chen Gang
2013-04-25 10:49                     ` [PATCH v5] " Chen Gang
2013-04-29 16:29                       ` David Miller
2013-05-02  1:11                         ` Chen Gang

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