* [PATCH] include/linux/skbuff.h: using '0xffff' instead of '~0U'
@ 2013-05-30 6:03 Chen Gang
2013-05-30 9:55 ` Chen Gang
` (2 more replies)
0 siblings, 3 replies; 19+ messages in thread
From: Chen Gang @ 2013-05-30 6:03 UTC (permalink / raw)
To: edumazet, Pravin Shelar, mgorman
Cc: David Miller, Andrew Morton, linux-kernel, netdev
Both 'transport_header' and 'mac_header' are u16, which are never equal
to '~0U'.
So need use '0xffff' 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]
...
Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
include/linux/skbuff.h | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 2e0ced1..03ba058 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1581,7 +1581,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 != 0xffff;
}
static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
@@ -1624,7 +1624,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 != 0xffff;
}
static inline void skb_reset_mac_header(struct sk_buff *skb)
--
1.7.7.6
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH] include/linux/skbuff.h: using '0xffff' instead of '~0U'
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-05-31 21:05 ` Andy Shevchenko
2 siblings, 0 replies; 19+ messages in thread
From: Chen Gang @ 2013-05-30 9:55 UTC (permalink / raw)
To: edumazet, Pravin Shelar, mgorman
Cc: David Miller, Andrew Morton, linux-kernel, netdev
It seems a good idea to "fgrep -rn '~0U'" all source code, and check
each one by one.
:-)
On 05/30/2013 02:03 PM, Chen Gang wrote:
>
> Both 'transport_header' and 'mac_header' are u16, which are never equal
> to '~0U'.
>
> So need use '0xffff' 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]
> ...
>
>
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
> include/linux/skbuff.h | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 2e0ced1..03ba058 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -1581,7 +1581,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 != 0xffff;
> }
>
> static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
> @@ -1624,7 +1624,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 != 0xffff;
> }
>
> static inline void skb_reset_mac_header(struct sk_buff *skb)
>
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] include/linux/skbuff.h: using '0xffff' instead of '~0U'
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
2 siblings, 1 reply; 19+ messages in thread
From: Ben Hutchings @ 2013-05-30 15:30 UTC (permalink / raw)
To: Chen Gang
Cc: edumazet, Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev
On Thu, 2013-05-30 at 14:03 +0800, Chen Gang wrote:
> Both 'transport_header' and 'mac_header' are u16, which are never equal
> to '~0U'.
>
> So need use '0xffff' instead of '~0U'.
...and give this magic number a name?
Ben.
> 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]
> ...
>
>
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
> include/linux/skbuff.h | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 2e0ced1..03ba058 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -1581,7 +1581,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 != 0xffff;
> }
>
> static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
> @@ -1624,7 +1624,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 != 0xffff;
> }
>
> static inline void skb_reset_mac_header(struct sk_buff *skb)
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] include/linux/skbuff.h: using '0xffff' instead of '~0U'
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-05-31 21:05 ` Andy Shevchenko
2013-06-03 9:23 ` Chen Gang
2 siblings, 1 reply; 19+ messages in thread
From: Andy Shevchenko @ 2013-05-31 21:05 UTC (permalink / raw)
To: Chen Gang
Cc: edumazet, Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev
On Thu, May 30, 2013 at 9:03 AM, Chen Gang <gang.chen@asianux.com> wrote:
>
> Both 'transport_header' and 'mac_header' are u16, which are never equal
> to '~0U'.
>
> So need use '0xffff' instead of '~0U'.
Why not "(u16)~0" ?
Or even better "!= USHORT_MAX"?
Or mac_header + 1 == 0, though it less clear.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] include/linux/skbuff.h: using '0xffff' instead of '~0U'
2013-05-30 15:30 ` Ben Hutchings
@ 2013-06-03 8:52 ` Chen Gang
0 siblings, 0 replies; 19+ messages in thread
From: Chen Gang @ 2013-06-03 8:52 UTC (permalink / raw)
To: Ben Hutchings
Cc: edumazet, Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev
On 05/30/2013 11:30 PM, Ben Hutchings wrote:
> On Thu, 2013-05-30 at 14:03 +0800, Chen Gang wrote:
>> > Both 'transport_header' and 'mac_header' are u16, which are never equal
>> > to '~0U'.
>> >
>> > So need use '0xffff' instead of '~0U'.
> ..and give this magic number a name?
It sounds a good idea. I will check which name is suitable for it, then
send patch v2, and please help to check it, too.
Thanks.
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] include/linux/skbuff.h: using '0xffff' instead of '~0U'
2013-05-31 21:05 ` Andy Shevchenko
@ 2013-06-03 9:23 ` Chen Gang
2013-06-03 10:14 ` Andy Shevchenko
0 siblings, 1 reply; 19+ messages in thread
From: Chen Gang @ 2013-06-03 9:23 UTC (permalink / raw)
To: Andy Shevchenko
Cc: edumazet, Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev, Ben Hutchings
On 06/01/2013 05:05 AM, Andy Shevchenko wrote:
> On Thu, May 30, 2013 at 9:03 AM, Chen Gang <gang.chen@asianux.com> wrote:
>> >
>> > Both 'transport_header' and 'mac_header' are u16, which are never equal
>> > to '~0U'.
>> >
>> > So need use '0xffff' instead of '~0U'.
> Why not "(u16)~0" ?
> Or even better "!= USHORT_MAX"?
>
> Or mac_header + 1 == 0, though it less clear.
It seems they are just the same as '0xffff' (are all 'magic' number).
We'd better to give a meaningful name to it just like Ben said.
Thanks.
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] include/linux/skbuff.h: using '0xffff' instead of '~0U'
2013-06-03 9:23 ` Chen Gang
@ 2013-06-03 10:14 ` Andy Shevchenko
2013-06-03 10:51 ` Chen Gang
0 siblings, 1 reply; 19+ messages in thread
From: Andy Shevchenko @ 2013-06-03 10:14 UTC (permalink / raw)
To: Chen Gang
Cc: edumazet, Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev, Ben Hutchings
On Mon, Jun 3, 2013 at 12:23 PM, Chen Gang <gang.chen@asianux.com> wrote:
> On 06/01/2013 05:05 AM, Andy Shevchenko wrote:
>> Why not "(u16)~0" ?
> We'd better to give a meaningful name to it just like Ben said.
Yeah, you could give a name, though I don't see this needs for
constants like (u16)~0. It's a usual way to mark some values
uninitialized.
Just an example from kernel:
/* This is limited by 16 bit "slot" numbers,
* and by available on-disk context storage.
*
* Also (u16)~0 is special (denotes a "free" extent).
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] include/linux/skbuff.h: using '0xffff' instead of '~0U'
2013-06-03 10:14 ` Andy Shevchenko
@ 2013-06-03 10:51 ` Chen Gang
2013-06-03 11:24 ` [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' " Chen Gang
0 siblings, 1 reply; 19+ messages in thread
From: Chen Gang @ 2013-06-03 10:51 UTC (permalink / raw)
To: Andy Shevchenko
Cc: edumazet, Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev, Ben Hutchings
On 06/03/2013 06:14 PM, Andy Shevchenko wrote:
> On Mon, Jun 3, 2013 at 12:23 PM, Chen Gang <gang.chen@asianux.com> wrote:
>> On 06/01/2013 05:05 AM, Andy Shevchenko wrote:
>
>>> Why not "(u16)~0" ?
>> We'd better to give a meaningful name to it just like Ben said.
>
> Yeah, you could give a name, though I don't see this needs for
> constants like (u16)~0. It's a usual way to mark some values
> uninitialized.
> Just an example from kernel:
>
> /* This is limited by 16 bit "slot" numbers,
> * and by available on-disk context storage.
> *
> * Also (u16)~0 is special (denotes a "free" extent).
>
After "fgrep -rn 'u16' * | fgrep '~0'", it seems better to define a
meaningful macro for it (e.g. "#define SKB_HEADER_WAS_UNSET 0xffff").
Thanks.
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' instead of '~0U'
2013-06-03 10:51 ` Chen Gang
@ 2013-06-03 11:24 ` Chen Gang
2013-06-03 11:34 ` Andy Shevchenko
2013-06-03 12:26 ` David Laight
0 siblings, 2 replies; 19+ messages in thread
From: Chen Gang @ 2013-06-03 11:24 UTC (permalink / raw)
To: Andy Shevchenko, edumazet
Cc: Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev, Ben Hutchings
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
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' instead of '~0U'
2013-06-03 11:24 ` [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' " Chen Gang
@ 2013-06-03 11:34 ` Andy Shevchenko
2013-06-03 11:46 ` Chen Gang
2013-06-03 12:26 ` David Laight
1 sibling, 1 reply; 19+ messages in thread
From: Andy Shevchenko @ 2013-06-03 11:34 UTC (permalink / raw)
To: Chen Gang
Cc: edumazet, Pravin Shelar, Mel Gorman, David Miller, Andrew Morton,
linux-kernel, netdev, Ben Hutchings
On Mon, Jun 3, 2013 at 2:24 PM, Chen Gang <gang.chen@asianux.com> wrote:
>
> 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.
Looks okay. Couple of questions below.
> --- 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)
Isn't better to use the same type as used in the structure description?
> --- 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;
Is it correct to assign transport_header here as well?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' instead of '~0U'
2013-06-03 11:34 ` Andy Shevchenko
@ 2013-06-03 11:46 ` Chen Gang
0 siblings, 0 replies; 19+ messages in thread
From: Chen Gang @ 2013-06-03 11:46 UTC (permalink / raw)
To: Andy Shevchenko
Cc: edumazet, Pravin Shelar, Mel Gorman, David Miller, Andrew Morton,
linux-kernel, netdev, Ben Hutchings
On 06/03/2013 07:34 PM, Andy Shevchenko wrote:
>> --- 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)
> Isn't better to use the same type as used in the structure description?
>
It sounds reasonable, I will wait 1 days, if no additional suggestions
or completions, I will send patch v3.
>> > --- 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;
> Is it correct to assign transport_header here as well?
At least, it is correct: they are in the same structure, and almost a
neighbor with each other.
Hmm... I guess that may be useless currently which will waste one
instruction.
But I still suggest to add it, it can avoid the new mistakes in the future.
Welcome another members to provide their suggestions for it.
Thanks.
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 19+ messages in thread
* RE: [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' instead of '~0U'
2013-06-03 11:24 ` [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' " Chen Gang
@ 2013-06-03 12:26 ` David Laight
2013-06-03 12:26 ` David Laight
1 sibling, 0 replies; 19+ messages in thread
From: David Laight @ 2013-06-03 12:26 UTC (permalink / raw)
To: Chen Gang, Andy Shevchenko, edumazet
Cc: Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev, Ben Hutchings
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 363 bytes --]
> +#define SKB_HEADER_UNSET_16 ((unsigned short) ~0U)
> +
The _16 part isn't really correct, the type could be changed
and then it would be wrong.
I think I might have used SKB_HEADER_OFFSET.
David
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply [flat|nested] 19+ messages in thread
* RE: [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' instead of '~0U'
@ 2013-06-03 12:26 ` David Laight
0 siblings, 0 replies; 19+ messages in thread
From: David Laight @ 2013-06-03 12:26 UTC (permalink / raw)
To: Chen Gang, Andy Shevchenko, edumazet
Cc: Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev, Ben Hutchings
> +#define SKB_HEADER_UNSET_16 ((unsigned short) ~0U)
> +
The _16 part isn't really correct, the type could be changed
and then it would be wrong.
I think I might have used SKB_HEADER_OFFSET.
David
^ permalink raw reply [flat|nested] 19+ messages in thread
* RE: [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' instead of '~0U'
2013-06-03 12:26 ` David Laight
@ 2013-06-03 12:47 ` David Laight
-1 siblings, 0 replies; 19+ messages in thread
From: David Laight @ 2013-06-03 12:47 UTC (permalink / raw)
To: David Laight, Chen Gang, Andy Shevchenko, edumazet
Cc: Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev, Ben Hutchings
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 518 bytes --]
> > +#define SKB_HEADER_UNSET_16 ((unsigned short) ~0U)
> > +
>
> The _16 part isn't really correct, the type could be changed
> and then it would be wrong.
>
> I think I might have used SKB_HEADER_OFFSET.
I meant SKB_HEADER_UNSET_OFFSET or SKB_HEADER_OFFSET_UNSET
> NrybXǧv^)Þº{.n+z^)w*jg\x1eÝ¢j/zÞ2Þ&)ß¡a\x7f\x1eGh\x0fj:+vwÙ¥
I've NFI what adds this!
David
ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
^ permalink raw reply [flat|nested] 19+ messages in thread
* RE: [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' instead of '~0U'
@ 2013-06-03 12:47 ` David Laight
0 siblings, 0 replies; 19+ messages in thread
From: David Laight @ 2013-06-03 12:47 UTC (permalink / raw)
To: David Laight, Chen Gang, Andy Shevchenko, edumazet
Cc: Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev, Ben Hutchings
> > +#define SKB_HEADER_UNSET_16 ((unsigned short) ~0U)
> > +
>
> The _16 part isn't really correct, the type could be changed
> and then it would be wrong.
>
> I think I might have used SKB_HEADER_OFFSET.
I meant SKB_HEADER_UNSET_OFFSET or SKB_HEADER_OFFSET_UNSET
> NrybXǧv^){.n+z^)w*jg\x1eݢj/zޖ2ޙ&)ߡa\x7f\x1eGh\x0fj:+vw٥
I've NFI what adds this!
David
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' instead of '~0U'
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
-1 siblings, 1 reply; 19+ messages in thread
From: Chen Gang @ 2013-06-05 0:44 UTC (permalink / raw)
To: David Laight
Cc: Andy Shevchenko, edumazet, Pravin Shelar, mgorman, David Miller,
Andrew Morton, linux-kernel, netdev, Ben Hutchings
On 06/03/2013 08:47 PM, David Laight wrote:
>>> +#define SKB_HEADER_UNSET_16 ((unsigned short) ~0U)
>>> > > +
>> >
>> > The _16 part isn't really correct, the type could be changed
>> > and then it would be wrong.
>> >
>> > I think I might have used SKB_HEADER_OFFSET.
> I meant SKB_HEADER_UNSET_OFFSET or SKB_HEADER_OFFSET_UNSET
>
It sound good, I choose the 2nd: 'SKB_HEADER_OFFSET_UNSET', for it may
be a 'noun', not a 'sentence'.
I will send patch v3 (also use '__u16' instead of 'unsigned short')
Thanks.
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v3] include/linux/skbuff.h: using '(__u16) ~0U' instead of '~0U'
2013-06-05 0:44 ` Chen Gang
@ 2013-06-05 0:54 ` Chen Gang
2013-06-05 8:36 ` David Miller
0 siblings, 1 reply; 19+ messages in thread
From: Chen Gang @ 2013-06-05 0:54 UTC (permalink / raw)
To: David Laight, Andy Shevchenko, edumazet
Cc: Pravin Shelar, mgorman, David Miller, Andrew Morton,
linux-kernel, netdev, Ben Hutchings
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..3314911 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_OFFSET_UNSET ((__u16) ~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_OFFSET_UNSET;
}
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_OFFSET_UNSET;
}
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..6808433 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_OFFSET_UNSET;
+ skb->transport_header = SKB_HEADER_OFFSET_UNSET;
#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_OFFSET_UNSET;
+ skb->transport_header = SKB_HEADER_OFFSET_UNSET;
#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_OFFSET_UNSET;
+ skb->transport_header = SKB_HEADER_OFFSET_UNSET;
#endif
/* make sure we initialize shinfo sequentially */
--
1.7.7.6
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v3] include/linux/skbuff.h: using '(__u16) ~0U' instead of '~0U'
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
0 siblings, 1 reply; 19+ messages in thread
From: David Miller @ 2013-06-05 8:36 UTC (permalink / raw)
To: gang.chen
Cc: David.Laight, andy.shevchenko, edumazet, pshelar, mgorman, akpm,
linux-kernel, netdev, bhutchings
From: Chen Gang <gang.chen@asianux.com>
Date: Wed, 05 Jun 2013 08:54:22 +0800
>
> 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>
Your patch doesn't apply to the tree because this has been fixed already
for several days by using "typeof(x) ~0U"
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v3] include/linux/skbuff.h: using '(__u16) ~0U' instead of '~0U'
2013-06-05 8:36 ` David Miller
@ 2013-06-05 11:15 ` Chen Gang
0 siblings, 0 replies; 19+ messages in thread
From: Chen Gang @ 2013-06-05 11:15 UTC (permalink / raw)
To: David Miller
Cc: David.Laight, andy.shevchenko, edumazet, pshelar, mgorman, akpm,
linux-kernel, netdev, bhutchings
On 06/05/2013 04:36 PM, David Miller wrote:
> From: Chen Gang <gang.chen@asianux.com>
> Date: Wed, 05 Jun 2013 08:54:22 +0800
>
>> >
>> > 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>
> Your patch doesn't apply to the tree because this has been fixed already
> for several days by using "typeof(x) ~0U"
>
>
OK, thanks.
--
Chen Gang
Asianux Corporation
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2013-06-05 11:16 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v2] include/linux/skbuff.h: using '(u16) ~0U' " Chen Gang
2013-06-03 11:34 ` Andy Shevchenko
2013-06-03 11:46 ` Chen Gang
2013-06-03 12:26 ` David Laight
2013-06-03 12:26 ` David Laight
2013-06-03 12:47 ` 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
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.