Skip to contentSkip to conversation

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

PATCH Superseded Chen Gang 5 participants 18 messages Apr 22, 2013 – May 2, 2013 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Chen Gang

author
#0 lore raw

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

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

---
 net/mac802154/mac802154.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/mac802154/mac802154.h +1 -1
index 5c9e021..c59309f 100644
@@ -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;
Signature · 1 line
1.7.7.6
#1 lore raw

Hello.

Quoted 45 lines · Chen Gang

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

---
  net/mac802154/mac802154.h |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
net/mac802154/mac802154.h +0 -0
index 5c9e021..c59309f 100644

net/mac802154/mac802154.h struct mac802154_sub_if_data { · line 91

Quoted 5 lines
net/mac802154/mac802154.h +1 -1
@@ -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

author
#2 lore raw
Quoted 15 lines · Sergei Shtylyov
Quoted 15 lines
---
  net/mac802154/mac802154.h |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
net/mac802154/mac802154.h +0 -0
index 5c9e021..c59309f 100644
@@ -88,7 +88,7 @@ struct mac802154_sub_if_data {
 
  #define mac802154_to_priv(_hw)    container_of(_hw, struct
 mac802154_priv, hw)
 
Quoted 8 lines

net/mac802154/mac802154.h struct mac802154_sub_if_data { · line 91

Quoted 2 lines
net/mac802154/mac802154.h +1 -1
-#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

Signature · 3 lines
Chen Gang

Asianux Corporation
author
#3 lore raw

PATCH v2 1/1 Net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

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

---
 net/mac802154/mac802154.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/mac802154/mac802154.h +1 -1
index 5c9e021..d48422e 100644
@@ -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;
Signature · 1 line
1.7.7.6
author
#4 lore raw

Re: [PATCH v2] Net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

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

Quoted 55 lines · Chen Gang

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

---
 net/mac802154/mac802154.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/mac802154/mac802154.h +1 -1
index 5c9e021..d48422e 100644
@@ -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;
Signature · 3 lines
Chen Gang

Asianux Corporation
author
#5 lore raw

PATCH v3 1/1 net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

In reply to Chen Gang

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

---
 net/mac802154/mac802154.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/mac802154/mac802154.h +1 -1
index 5c9e021..d48422e 100644
@@ -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;
Signature · 1 line
1.7.7.6
maintainer
#6 lore raw

Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

From: Chen Gang <[email protected]>
Date: Tue, 23 Apr 2013 19:24:36 +0800

Quoted 14 lines

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

...

Quoted 1 line

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.

author
#7 lore raw

Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

Quoted 16 lines · David Miller

From: Chen Gang <[email protected]>
Date: Tue, 23 Apr 2013 19:24:36 +0800

Quoted 13 lines
Quoted 13 lines

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'

Quoted 9 lines
Quoted 1 line
Quoted 1 line

(after use '0xff' instead of '~(u8)0', it will output 'equal')

...

Quoted 1 line
Quoted 1 line

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.

Signature · 3 lines
Chen Gang

Asianux Corporation
maintainer
#8 lore raw

Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

From: Chen Gang <[email protected]>
Date: Thu, 25 Apr 2013 16:43:14 +0800

Quoted 1 line

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

#11 lore raw

Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

In reply to a message not in the archive

Hi Chen,

Quoted 9 lines · Chen Gang
Quoted 3 lines · David Miller

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

Quoted 5 lines

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,

Signature · 17 lines
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel
author
#12 lore raw

Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

Quoted 16 lines · Christophe Aeschlimann

Hi Chen,

Quoted 13 lines · Chen Gang
Quoted 13 lines · David Miller
Quoted 3 lines
Quoted 3 lines

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)

Quoted 8 lines
Quoted 1 line
Quoted 1 line

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.

Signature · 3 lines
Chen Gang

Asianux Corporation
author
#9 lore raw

Re: [PATCH v3] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

In reply to David Miller
Quoted 9 lines · David Miller

From: Chen Gang <[email protected]>
Date: Thu, 25 Apr 2013 16:43:14 +0800

Quoted 1 line
Quoted 1 line

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

Signature · 3 lines
Chen Gang

Asianux Corporation
author
#13 lore raw

Re: [PATCH v4] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

In reply to Christophe Aeschlimann

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

---
 net/mac802154/mac802154.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac802154/mac802154.h +1 -1
index a4dcaf1..703c121 100644
@@ -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;
Signature · 1 line
1.7.11.7
#14 lore raw

Re: [PATCH v4] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

Quoted 6 lines · Chen Gang

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?

Quoted 47 lines

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

---
  net/mac802154/mac802154.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/mac802154/mac802154.h +1 -1
index a4dcaf1..703c121 100644
@@ -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;
author
#15 lore raw

Re: [PATCH v4] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

Quoted 7 lines · Daniel Borkmann

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.

:-)

Signature · 3 lines
Chen Gang

Asianux Corporation
author
#16 lore raw

PATCH v5 1/1 net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W

In reply to Daniel Borkmann

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.

---
 net/mac802154/mac802154.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac802154/mac802154.h +1 -1
index a4dcaf1..703c121 100644
@@ -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;
Signature · 1 line
1.7.11.7
maintainer Applied
#17 lore raw

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

From: Chen Gang <[email protected]>
Date: Thu, 25 Apr 2013 18:49:55 +0800

Quoted 10 lines

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.

Applied, thanks.

author
#18 lore raw

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

Quoted 8 lines · David Miller

From: Chen Gang <[email protected]>
Date: Thu, 25 Apr 2013 18:49:55 +0800

Quoted 5 lines

Change MAC802154_CHAN_NONE from ~(u8)0 to 0xff, or the comparison in mac802154_wpan_xmit() for ``chan == MAC802154_CHAN_NONE'' will not succeed.

Quoted 9 lines
Quoted 5 lines

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

Applied, thanks.

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

Signature · 3 lines
Chen Gang

Asianux Corporation