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 <[email protected]>
---
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
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 <[email protected]>
> ---
> 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
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 <[email protected]>
> ---
> 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.
On Thu, May 30, 2013 at 9:03 AM, Chen Gang <[email protected]> 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
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
On 06/01/2013 05:05 AM, Andy Shevchenko wrote:
> On Thu, May 30, 2013 at 9:03 AM, Chen Gang <[email protected]> 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
On Mon, Jun 3, 2013 at 12:23 PM, Chen Gang <[email protected]> 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
On 06/03/2013 06:14 PM, Andy Shevchenko wrote:
> On Mon, Jun 3, 2013 at 12:23 PM, Chen Gang <[email protected]> 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
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 <[email protected]>
---
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
On Mon, Jun 3, 2013 at 2:24 PM, Chen Gang <[email protected]> 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
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
> +#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?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m????????????I?
> > +#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ݢj/zޖ2ޙ&)ߡaGhj:+vw٥
I've NFI what adds this!
David
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m????????????I?
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 <[email protected]>
---
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
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
From: Chen Gang <[email protected]>
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 <[email protected]>
Your patch doesn't apply to the tree because this has been fixed already
for several days by using "typeof(x) ~0U"
On 06/05/2013 04:36 PM, David Miller wrote:
> From: Chen Gang <[email protected]>
> 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 <[email protected]>
> 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