netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen@asianux.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>, edumazet@google.com
Cc: Pravin Shelar <pshelar@nicira.com>,
	mgorman@suse.de, David Miller <davem@davemloft.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	netdev <netdev@vger.kernel.org>,
	Ben Hutchings <bhutchings@solarflare.com>
Subject: [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' instead of '~0U'
Date: Mon, 03 Jun 2013 19:24:04 +0800	[thread overview]
Message-ID: <51AC7CD4.2060801@asianux.com> (raw)
In-Reply-To: <51AC7546.4010002@asianux.com>


Both 'transport_header' and 'mac_header' are u16, which are never equal
to '~0U'.

So need use '(u16) ~0U' instead of '~0U'.

The related warning (with EXTRA_CFLAGS=-W ARCH=m68k for allmodconfig)
  include/linux/skbuff.h:1587:2: warning: comparison is always true due to limited range of data type [-Wtype-limits]
  ...

Use meaningful macro instead of hard code number, and better to
initialize 'skb->transport_header' in __alloc_skb_head(), too.


Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 include/linux/skbuff.h |    6 ++++--
 net/core/skbuff.c      |   11 ++++++-----
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 5f93119..59493f8 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -40,6 +40,8 @@
 #define CHECKSUM_COMPLETE 2
 #define CHECKSUM_PARTIAL 3
 
+#define SKB_HEADER_UNSET_16	((unsigned short) ~0U)
+
 #define SKB_DATA_ALIGN(X)	(((X) + (SMP_CACHE_BYTES - 1)) & \
 				 ~(SMP_CACHE_BYTES - 1))
 #define SKB_WITH_OVERHEAD(X)	\
@@ -1593,7 +1595,7 @@ static inline void skb_set_inner_mac_header(struct sk_buff *skb,
 }
 static inline bool skb_transport_header_was_set(const struct sk_buff *skb)
 {
-	return skb->transport_header != ~0U;
+	return skb->transport_header != SKB_HEADER_UNSET_16;
 }
 
 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
@@ -1636,7 +1638,7 @@ static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
 
 static inline int skb_mac_header_was_set(const struct sk_buff *skb)
 {
-	return skb->mac_header != ~0U;
+	return skb->mac_header != SKB_HEADER_UNSET_16;
 }
 
 static inline void skb_reset_mac_header(struct sk_buff *skb)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index f45de07..18c6974 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -200,7 +200,8 @@ struct sk_buff *__alloc_skb_head(gfp_t gfp_mask, int node)
 	atomic_set(&skb->users, 1);
 
 #ifdef NET_SKBUFF_DATA_USES_OFFSET
-	skb->mac_header = (__u16) ~0U;
+	skb->mac_header = SKB_HEADER_UNSET_16;
+	skb->transport_header = SKB_HEADER_UNSET_16;
 #endif
 out:
 	return skb;
@@ -276,8 +277,8 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
 	skb_reset_tail_pointer(skb);
 	skb->end = skb->tail + size;
 #ifdef NET_SKBUFF_DATA_USES_OFFSET
-	skb->mac_header = (__u16) ~0U;
-	skb->transport_header = (__u16) ~0U;
+	skb->mac_header = SKB_HEADER_UNSET_16;
+	skb->transport_header = SKB_HEADER_UNSET_16;
 #endif
 
 	/* make sure we initialize shinfo sequentially */
@@ -345,8 +346,8 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size)
 	skb_reset_tail_pointer(skb);
 	skb->end = skb->tail + size;
 #ifdef NET_SKBUFF_DATA_USES_OFFSET
-	skb->mac_header = (__u16) ~0U;
-	skb->transport_header = (__u16) ~0U;
+	skb->mac_header = SKB_HEADER_UNSET_16;
+	skb->transport_header = SKB_HEADER_UNSET_16;
 #endif
 
 	/* make sure we initialize shinfo sequentially */
-- 
1.7.7.6

  reply	other threads:[~2013-06-03 11:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-30  6:03 [PATCH] include/linux/skbuff.h: using '0xffff' instead of '~0U' Chen Gang
2013-05-30  9:55 ` Chen Gang
2013-05-30 15:30 ` Ben Hutchings
2013-06-03  8:52   ` Chen Gang
2013-05-31 21:05 ` Andy Shevchenko
2013-06-03  9:23   ` Chen Gang
2013-06-03 10:14     ` Andy Shevchenko
2013-06-03 10:51       ` Chen Gang
2013-06-03 11:24         ` Chen Gang [this message]
2013-06-03 11:34           ` [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' " Andy Shevchenko
2013-06-03 11:46             ` Chen Gang
2013-06-03 12:26           ` David Laight
2013-06-03 12:47             ` David Laight
2013-06-05  0:44               ` Chen Gang
2013-06-05  0:54                 ` [PATCH v3] include/linux/skbuff.h: using '(__u16) " Chen Gang
2013-06-05  8:36                   ` David Miller
2013-06-05 11:15                     ` 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=51AC7CD4.2060801@asianux.com \
    --to=gang.chen@asianux.com \
    --cc=akpm@linux-foundation.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=bhutchings@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=netdev@vger.kernel.org \
    --cc=pshelar@nicira.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).