From: Daniel Borkmann <dborkman@redhat.com>
To: Chen Gang <gang.chen@asianux.com>
Cc: David Miller <davem@davemloft.net>,
Christophe Aeschlimann <c.aeschlimann@acn-group.ch>,
sergei.shtylyov@cogentembedded.com,
alex.bluesman.smirnov@gmail.com, dbaryshkov@gmail.com,
linux-zigbee-devel@lists.sourceforge.net, netdev@vger.kernel.org
Subject: Re: [PATCH v4] net: mac802154: comparision issue of type cast, finding by EXTRA_CFLAGS=-W
Date: Thu, 25 Apr 2013 11:59:06 +0200 [thread overview]
Message-ID: <5178FE6A.3050108@redhat.com> (raw)
In-Reply-To: <5178FA0D.8060009@asianux.com>
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;
>
next prev parent reply other threads:[~2013-04-25 9:59 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5178FE6A.3050108@redhat.com \
--to=dborkman@redhat.com \
--cc=alex.bluesman.smirnov@gmail.com \
--cc=c.aeschlimann@acn-group.ch \
--cc=davem@davemloft.net \
--cc=dbaryshkov@gmail.com \
--cc=gang.chen@asianux.com \
--cc=linux-zigbee-devel@lists.sourceforge.net \
--cc=netdev@vger.kernel.org \
--cc=sergei.shtylyov@cogentembedded.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).