* [Patch net-next] net: clean up skb headers code @ 2013-05-29 6:09 Cong Wang 2013-05-29 6:36 ` David Miller 0 siblings, 1 reply; 19+ messages in thread From: Cong Wang @ 2013-05-29 6:09 UTC (permalink / raw) To: netdev; +Cc: Cong Wang, David S. Miller, Simon Horman commit 1a37e412a0225fcba5587 (net: Use 16bits for *_headers fields of struct skbuff) converts skb->*_header to u16, therefore 1) we could just use 0xFFFFF instead of (__u16) ~0U 2) some #if NET_SKBUFF_DATA_USES_OFFSET is useless now. Cc: David S. Miller <davem@davemloft.net> Cc: Simon Horman <horms@verge.net.au> Signed-off-by: Cong Wang <amwang@redhat.com> --- diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 8f2b830..3c896b7 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1584,7 +1584,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) @@ -1627,7 +1627,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) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index f45de07..0c3742f 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -199,9 +199,7 @@ struct sk_buff *__alloc_skb_head(gfp_t gfp_mask, int node) skb->truesize = sizeof(struct sk_buff); atomic_set(&skb->users, 1); -#ifdef NET_SKBUFF_DATA_USES_OFFSET - skb->mac_header = (__u16) ~0U; -#endif + skb->mac_header = 0xFFFF; out: return skb; } @@ -275,10 +273,8 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, skb->data = data; 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; -#endif + skb->mac_header = 0xFFFF; + skb->transport_header = 0xFFFF; /* make sure we initialize shinfo sequentially */ shinfo = skb_shinfo(skb); @@ -344,10 +340,8 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size) skb->data = data; 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; -#endif + skb->mac_header = 0xFFFF; + skb->transport_header = 0xFFFF; /* make sure we initialize shinfo sequentially */ shinfo = skb_shinfo(skb); ^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-29 6:09 [Patch net-next] net: clean up skb headers code Cong Wang @ 2013-05-29 6:36 ` David Miller 2013-05-29 6:48 ` Cong Wang 2013-05-29 19:34 ` Ben Hutchings 0 siblings, 2 replies; 19+ messages in thread From: David Miller @ 2013-05-29 6:36 UTC (permalink / raw) To: amwang; +Cc: netdev, horms From: Cong Wang <amwang@redhat.com> Date: Wed, 29 May 2013 14:09:00 +0800 > commit 1a37e412a0225fcba5587 (net: Use 16bits for *_headers > fields of struct skbuff) converts skb->*_header to u16, > therefore 1) we could just use 0xFFFFF instead of (__u16) ~0U > 2) some #if NET_SKBUFF_DATA_USES_OFFSET is useless now. > > > Cc: David S. Miller <davem@davemloft.net> > Cc: Simon Horman <horms@verge.net.au> > Signed-off-by: Cong Wang <amwang@redhat.com> I want to use something that will either break the build or automatically work if the type changes again. So something like "X = (typeof(X)) ~0U;". ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-29 6:36 ` David Miller @ 2013-05-29 6:48 ` Cong Wang 2013-05-29 6:49 ` David Miller 2013-05-29 19:34 ` Ben Hutchings 1 sibling, 1 reply; 19+ messages in thread From: Cong Wang @ 2013-05-29 6:48 UTC (permalink / raw) To: David Miller; +Cc: netdev, horms On Tue, 2013-05-28 at 23:36 -0700, David Miller wrote: > From: Cong Wang <amwang@redhat.com> > Date: Wed, 29 May 2013 14:09:00 +0800 > > > commit 1a37e412a0225fcba5587 (net: Use 16bits for *_headers > > fields of struct skbuff) converts skb->*_header to u16, > > therefore 1) we could just use 0xFFFFF instead of (__u16) ~0U > > 2) some #if NET_SKBUFF_DATA_USES_OFFSET is useless now. > > > > > > Cc: David S. Miller <davem@davemloft.net> > > Cc: Simon Horman <horms@verge.net.au> > > Signed-off-by: Cong Wang <amwang@redhat.com> > > I want to use something that will either break the build or > automatically work if the type changes again. > > So something like "X = (typeof(X)) ~0U;". Yeah, this is even better. I will update this patch. Thanks. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-29 6:48 ` Cong Wang @ 2013-05-29 6:49 ` David Miller 0 siblings, 0 replies; 19+ messages in thread From: David Miller @ 2013-05-29 6:49 UTC (permalink / raw) To: amwang; +Cc: netdev, horms From: Cong Wang <amwang@redhat.com> Date: Wed, 29 May 2013 14:48:06 +0800 > On Tue, 2013-05-28 at 23:36 -0700, David Miller wrote: >> From: Cong Wang <amwang@redhat.com> >> Date: Wed, 29 May 2013 14:09:00 +0800 >> >> > commit 1a37e412a0225fcba5587 (net: Use 16bits for *_headers >> > fields of struct skbuff) converts skb->*_header to u16, >> > therefore 1) we could just use 0xFFFFF instead of (__u16) ~0U >> > 2) some #if NET_SKBUFF_DATA_USES_OFFSET is useless now. >> > >> > >> > Cc: David S. Miller <davem@davemloft.net> >> > Cc: Simon Horman <horms@verge.net.au> >> > Signed-off-by: Cong Wang <amwang@redhat.com> >> >> I want to use something that will either break the build or >> automatically work if the type changes again. >> >> So something like "X = (typeof(X)) ~0U;". > > Yeah, this is even better. I will update this patch. Please sumbit it against Simon's series, which I'm about to push to net-next. Thanks. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-29 6:36 ` David Miller 2013-05-29 6:48 ` Cong Wang @ 2013-05-29 19:34 ` Ben Hutchings 2013-05-29 19:44 ` Antonio Quartulli ` (2 more replies) 1 sibling, 3 replies; 19+ messages in thread From: Ben Hutchings @ 2013-05-29 19:34 UTC (permalink / raw) To: David Miller; +Cc: amwang, netdev, horms On Tue, 2013-05-28 at 23:36 -0700, David Miller wrote: > From: Cong Wang <amwang@redhat.com> > Date: Wed, 29 May 2013 14:09:00 +0800 > > > commit 1a37e412a0225fcba5587 (net: Use 16bits for *_headers > > fields of struct skbuff) converts skb->*_header to u16, > > therefore 1) we could just use 0xFFFFF instead of (__u16) ~0U > > 2) some #if NET_SKBUFF_DATA_USES_OFFSET is useless now. > > > > > > Cc: David S. Miller <davem@davemloft.net> > > Cc: Simon Horman <horms@verge.net.au> > > Signed-off-by: Cong Wang <amwang@redhat.com> > > I want to use something that will either break the build or > automatically work if the type changes again. > > So something like "X = (typeof(X)) ~0U;". I think you mean ~(typeof(X))0. Ben. -- 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 net-next] net: clean up skb headers code 2013-05-29 19:34 ` Ben Hutchings @ 2013-05-29 19:44 ` Antonio Quartulli 2013-05-29 21:02 ` Ben Hutchings 2013-05-30 1:59 ` Cong Wang 2013-05-30 10:40 ` David Miller 2 siblings, 1 reply; 19+ messages in thread From: Antonio Quartulli @ 2013-05-29 19:44 UTC (permalink / raw) To: Ben Hutchings; +Cc: David Miller, amwang, netdev, horms [-- Attachment #1: Type: text/plain, Size: 1144 bytes --] On Wed, May 29, 2013 at 08:34:33PM +0100, Ben Hutchings wrote: > On Tue, 2013-05-28 at 23:36 -0700, David Miller wrote: > > From: Cong Wang <amwang@redhat.com> > > Date: Wed, 29 May 2013 14:09:00 +0800 > > > > > commit 1a37e412a0225fcba5587 (net: Use 16bits for *_headers > > > fields of struct skbuff) converts skb->*_header to u16, > > > therefore 1) we could just use 0xFFFFF instead of (__u16) ~0U > > > 2) some #if NET_SKBUFF_DATA_USES_OFFSET is useless now. > > > > > > > > > Cc: David S. Miller <davem@davemloft.net> > > > Cc: Simon Horman <horms@verge.net.au> > > > Signed-off-by: Cong Wang <amwang@redhat.com> > > > > I want to use something that will either break the build or > > automatically work if the type changes again. > > > > So something like "X = (typeof(X)) ~0U;". > > I think you mean ~(typeof(X))0. Am I wrong or you should cast the value once again, like this: ((typeof(X))~(typeof(X))0) because the ~ operator will implicitly cast the argument to int (if I remember correctly). Cheers, -- Antonio Quartulli ..each of us alone is worth nothing.. Ernesto "Che" Guevara [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-29 19:44 ` Antonio Quartulli @ 2013-05-29 21:02 ` Ben Hutchings 2013-05-30 8:59 ` Antonio Quartulli 2013-05-30 11:41 ` David Laight 0 siblings, 2 replies; 19+ messages in thread From: Ben Hutchings @ 2013-05-29 21:02 UTC (permalink / raw) To: Antonio Quartulli; +Cc: David Miller, amwang, netdev, horms On Wed, 2013-05-29 at 21:44 +0200, Antonio Quartulli wrote: > On Wed, May 29, 2013 at 08:34:33PM +0100, Ben Hutchings wrote: > > On Tue, 2013-05-28 at 23:36 -0700, David Miller wrote: > > > From: Cong Wang <amwang@redhat.com> > > > Date: Wed, 29 May 2013 14:09:00 +0800 > > > > > > > commit 1a37e412a0225fcba5587 (net: Use 16bits for *_headers > > > > fields of struct skbuff) converts skb->*_header to u16, > > > > therefore 1) we could just use 0xFFFFF instead of (__u16) ~0U > > > > 2) some #if NET_SKBUFF_DATA_USES_OFFSET is useless now. > > > > > > > > > > > > Cc: David S. Miller <davem@davemloft.net> > > > > Cc: Simon Horman <horms@verge.net.au> > > > > Signed-off-by: Cong Wang <amwang@redhat.com> > > > > > > I want to use something that will either break the build or > > > automatically work if the type changes again. > > > > > > So something like "X = (typeof(X)) ~0U;". > > > > I think you mean ~(typeof(X))0. > > Am I wrong or you should cast the value once again, like this: > > ((typeof(X))~(typeof(X))0) > > because the ~ operator will implicitly cast the argument to int (if I remember > correctly). It will promote to at least int, but that still results in the right value and doesn't provoke a warning. Try this test (with -Wall -Wextra): #include <stdio.h> #define ALL_ONES(v) (~(typeof(v))0) /* #define ALL_ONES(v) (typeof(v))~0U) */ int main(void) { char a = ALL_ONES(a); unsigned char b = ALL_ONES(b); short c = ALL_ONES(c); unsigned short d = ALL_ONES(d); int e = ALL_ONES(e); unsigned int f = ALL_ONES(f); long g = ALL_ONES(g); unsigned long h = ALL_ONES(h); long long i = ALL_ONES(i); unsigned long long j = ALL_ONES(j); printf("%hhx %hhx %hx %hx %x %x %lx %lx %llx %llx\n", a, b, c, d, e, f, g, h, i, j); return 0; } -- 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 net-next] net: clean up skb headers code 2013-05-29 21:02 ` Ben Hutchings @ 2013-05-30 8:59 ` Antonio Quartulli 2013-05-30 11:41 ` David Laight 1 sibling, 0 replies; 19+ messages in thread From: Antonio Quartulli @ 2013-05-30 8:59 UTC (permalink / raw) To: Ben Hutchings; +Cc: David Miller, amwang, netdev, horms [-- Attachment #1: Type: text/plain, Size: 1803 bytes --] On Wed, May 29, 2013 at 10:02:06PM +0100, Ben Hutchings wrote: > On Wed, 2013-05-29 at 21:44 +0200, Antonio Quartulli wrote: > > On Wed, May 29, 2013 at 08:34:33PM +0100, Ben Hutchings wrote: > > > On Tue, 2013-05-28 at 23:36 -0700, David Miller wrote: > > > > From: Cong Wang <amwang@redhat.com> > > > > Date: Wed, 29 May 2013 14:09:00 +0800 > > > > > > > > > commit 1a37e412a0225fcba5587 (net: Use 16bits for *_headers > > > > > fields of struct skbuff) converts skb->*_header to u16, > > > > > therefore 1) we could just use 0xFFFFF instead of (__u16) ~0U > > > > > 2) some #if NET_SKBUFF_DATA_USES_OFFSET is useless now. > > > > > > > > > > > > > > > Cc: David S. Miller <davem@davemloft.net> > > > > > Cc: Simon Horman <horms@verge.net.au> > > > > > Signed-off-by: Cong Wang <amwang@redhat.com> > > > > > > > > I want to use something that will either break the build or > > > > automatically work if the type changes again. > > > > > > > > So something like "X = (typeof(X)) ~0U;". > > > > > > I think you mean ~(typeof(X))0. > > > > Am I wrong or you should cast the value once again, like this: > > > > ((typeof(X))~(typeof(X))0) > > > > because the ~ operator will implicitly cast the argument to int (if I remember > > correctly). > > It will promote to at least int, but that still results in the right > value and doesn't provoke a warning. Try this test (with -Wall > -Wextra): thanks for the test code Ben. Yeah it gives the results you expected. Then I don't know why somebody suggested us to do this double cast in batman-adv when we wanted to obtain the same. At this point I'll remove the double cast in our code too. Thanks. Cheers, -- Antonio Quartulli ..each of us alone is worth nothing.. Ernesto "Che" Guevara [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* RE: [Patch net-next] net: clean up skb headers code 2013-05-29 21:02 ` Ben Hutchings 2013-05-30 8:59 ` Antonio Quartulli @ 2013-05-30 11:41 ` David Laight 2013-05-30 11:45 ` Antonio Quartulli 1 sibling, 1 reply; 19+ messages in thread From: David Laight @ 2013-05-30 11:41 UTC (permalink / raw) To: Ben Hutchings, Antonio Quartulli; +Cc: David Miller, amwang, netdev, horms > > > > I want to use something that will either break the build or > > > > automatically work if the type changes again. > > > > > > > > So something like "X = (typeof(X)) ~0U;". > > > > > > I think you mean ~(typeof(X))0. > > > > Am I wrong or you should cast the value once again, like this: > > > > ((typeof(X))~(typeof(X))0) > > > > because the ~ operator will implicitly cast the argument to int (if I remember > > correctly). > > It will promote to at least int, but that still results in the right > value and doesn't provoke a warning. Try this test (with -Wall > -Wextra): > > #include <stdio.h> > > #define ALL_ONES(v) (~(typeof(v))0) > /* #define ALL_ONES(v) (typeof(v))~0U) */ > > int main(void) > { > char a = ALL_ONES(a); > unsigned char b = ALL_ONES(b); > short c = ALL_ONES(c); > unsigned short d = ALL_ONES(d); > int e = ALL_ONES(e); > unsigned int f = ALL_ONES(f); > long g = ALL_ONES(g); > unsigned long h = ALL_ONES(h); > long long i = ALL_ONES(i); > unsigned long long j = ALL_ONES(j); > > printf("%hhx %hhx %hx %hx %x %x %lx %lx %llx %llx\n", > a, b, c, d, e, f, g, h, i, j); > return 0; > } The printf format is masking the high bits for you. If you change to: printf("%x %x %x %x %x %x %lx %lx %llx %llx\n", ...) you get different values. To get the 'expected' values you need casts both sides of the ~ David ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-30 11:41 ` David Laight @ 2013-05-30 11:45 ` Antonio Quartulli 2013-05-30 12:12 ` David Laight 0 siblings, 1 reply; 19+ messages in thread From: Antonio Quartulli @ 2013-05-30 11:45 UTC (permalink / raw) To: David Laight; +Cc: Ben Hutchings, David Miller, amwang, netdev, horms [-- Attachment #1: Type: text/plain, Size: 1843 bytes --] On Thu, May 30, 2013 at 12:41:03PM +0100, David Laight wrote: > > > > > I want to use something that will either break the build or > > > > > automatically work if the type changes again. > > > > > > > > > > So something like "X = (typeof(X)) ~0U;". > > > > > > > > I think you mean ~(typeof(X))0. > > > > > > Am I wrong or you should cast the value once again, like this: > > > > > > ((typeof(X))~(typeof(X))0) > > > > > > because the ~ operator will implicitly cast the argument to int (if I remember > > > correctly). > > > > It will promote to at least int, but that still results in the right > > value and doesn't provoke a warning. Try this test (with -Wall > > -Wextra): > > > > #include <stdio.h> > > > > #define ALL_ONES(v) (~(typeof(v))0) > > /* #define ALL_ONES(v) (typeof(v))~0U) */ > > > > int main(void) > > { > > char a = ALL_ONES(a); > > unsigned char b = ALL_ONES(b); > > short c = ALL_ONES(c); > > unsigned short d = ALL_ONES(d); > > int e = ALL_ONES(e); > > unsigned int f = ALL_ONES(f); > > long g = ALL_ONES(g); > > unsigned long h = ALL_ONES(h); > > long long i = ALL_ONES(i); > > unsigned long long j = ALL_ONES(j); > > > > printf("%hhx %hhx %hx %hx %x %x %lx %lx %llx %llx\n", > > a, b, c, d, e, f, g, h, i, j); > > return 0; > > } > > The printf format is masking the high bits for you. > If you change to: > printf("%x %x %x %x %x %x %lx %lx %llx %llx\n", ...) > you get different values. > To get the 'expected' values you need casts both sides of the ~ I tried with 19 printf("%x %x %x %x %x %x %lx %lx %llx %llx\n", but I still see all FF. Somewhere else we have some hidden conversion? Cheers, -- Antonio Quartulli ..each of us alone is worth nothing.. Ernesto "Che" Guevara [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* RE: [Patch net-next] net: clean up skb headers code 2013-05-30 11:45 ` Antonio Quartulli @ 2013-05-30 12:12 ` David Laight 2013-05-30 12:22 ` David Laight 2013-05-30 12:23 ` Antonio Quartulli 0 siblings, 2 replies; 19+ messages in thread From: David Laight @ 2013-05-30 12:12 UTC (permalink / raw) To: Antonio Quartulli; +Cc: Ben Hutchings, David Miller, amwang, netdev, horms > > > > > > I want to use something that will either break the build or > > > > > > automatically work if the type changes again. > > > > > > > > > > > > So something like "X = (typeof(X)) ~0U;". > > > > > > > > > > I think you mean ~(typeof(X))0. > > > > > > > > Am I wrong or you should cast the value once again, like this: > > > > > > > > ((typeof(X))~(typeof(X))0) > > > > > > > > because the ~ operator will implicitly cast the argument to int (if I remember > > > > correctly). > > > > > > It will promote to at least int, but that still results in the right > > > value and doesn't provoke a warning. Try this test (with -Wall > > > -Wextra): > > > > > > #include <stdio.h> > > > > > > #define ALL_ONES(v) (~(typeof(v))0) > > > /* #define ALL_ONES(v) (typeof(v))~0U) */ > > > > > > int main(void) > > > { > > > char a = ALL_ONES(a); > > > unsigned char b = ALL_ONES(b); > > > short c = ALL_ONES(c); > > > unsigned short d = ALL_ONES(d); > > > int e = ALL_ONES(e); > > > unsigned int f = ALL_ONES(f); > > > long g = ALL_ONES(g); > > > unsigned long h = ALL_ONES(h); > > > long long i = ALL_ONES(i); > > > unsigned long long j = ALL_ONES(j); > > > > > > printf("%hhx %hhx %hx %hx %x %x %lx %lx %llx %llx\n", > > > a, b, c, d, e, f, g, h, i, j); > > > return 0; > > > } > > > > The printf format is masking the high bits for you. > > If you change to: > > printf("%x %x %x %x %x %x %lx %lx %llx %llx\n", ...) > > you get different values. > > To get the 'expected' values you need casts both sides of the ~ > > I tried with > > 19 printf("%x %x %x %x %x %x %lx %lx %llx %llx\n", > > but I still see all FF. > > Somewhere else we have some hidden conversion? Of course - we need to look at the value that ALL_ONES() generates in an expression. So the test print needs to be: printf("%hhx %hhx %hx %hx %x %x %lx %lx %llx %llx\n", ALL_ONES(a), ALL_ONES(b), ALL_ONES(c), ALL_ONES(d), ALL_ONES(e), ALL_ONES(f), ALL_ONES(g), ALL_ONES(h), ALL_ONES(i), ALL_ONES(j)); which then gives 0xffffffff for the first 4 entries. David ^ permalink raw reply [flat|nested] 19+ messages in thread
* RE: [Patch net-next] net: clean up skb headers code 2013-05-30 12:12 ` David Laight @ 2013-05-30 12:22 ` David Laight 2013-05-30 12:24 ` Antonio Quartulli 2013-05-30 12:23 ` Antonio Quartulli 1 sibling, 1 reply; 19+ messages in thread From: David Laight @ 2013-05-30 12:22 UTC (permalink / raw) To: David Laight, Antonio Quartulli Cc: Ben Hutchings, David Miller, amwang, netdev, horms > Of course - we need to look at the value that ALL_ONES() > generates in an expression. So the test print needs to be: > printf("%hhx %hhx %hx %hx %x %x %lx %lx %llx %llx\n", > ALL_ONES(a), ALL_ONES(b), ALL_ONES(c), ALL_ONES(d), > ALL_ONES(e), ALL_ONES(f), ALL_ONES(g), ALL_ONES(h), > ALL_ONES(i), ALL_ONES(j)); > which then gives 0xffffffff for the first 4 entries. Except I copied the wrong format line :-( It should be: printf("%x %x %x %x %x %x %lx %lx %llx %llx\n", ALL_ONES(a), ALL_ONES(b), ALL_ONES(c), ALL_ONES(d), ALL_ONES(e), ALL_ONES(f), ALL_ONES(g), ALL_ONES(h), ALL_ONES(i), ALL_ONES(j)); David ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-30 12:22 ` David Laight @ 2013-05-30 12:24 ` Antonio Quartulli 2013-05-30 12:40 ` David Laight 0 siblings, 1 reply; 19+ messages in thread From: Antonio Quartulli @ 2013-05-30 12:24 UTC (permalink / raw) To: David Laight; +Cc: Ben Hutchings, David Miller, amwang, netdev, horms [-- Attachment #1: Type: text/plain, Size: 1052 bytes --] On Thu, May 30, 2013 at 01:22:14PM +0100, David Laight wrote: > > Of course - we need to look at the value that ALL_ONES() > > generates in an expression. So the test print needs to be: > > printf("%hhx %hhx %hx %hx %x %x %lx %lx %llx %llx\n", > > ALL_ONES(a), ALL_ONES(b), ALL_ONES(c), ALL_ONES(d), > > ALL_ONES(e), ALL_ONES(f), ALL_ONES(g), ALL_ONES(h), > > ALL_ONES(i), ALL_ONES(j)); > > which then gives 0xffffffff for the first 4 entries. > > Except I copied the wrong format line :-( It should be: > printf("%x %x %x %x %x %x %lx %lx %llx %llx\n", > ALL_ONES(a), ALL_ONES(b), ALL_ONES(c), ALL_ONES(d), > ALL_ONES(e), ALL_ONES(f), ALL_ONES(g), ALL_ONES(h), > ALL_ONES(i), ALL_ONES(j)); Oh ok, I see the issue now. So the problem is that this value gets bigger than what the maximal value for the type passed as argument is supposed to be. I think the issue is clear now and why a double cast is good. Cheers, -- Antonio Quartulli ..each of us alone is worth nothing.. Ernesto "Che" Guevara [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* RE: [Patch net-next] net: clean up skb headers code 2013-05-30 12:24 ` Antonio Quartulli @ 2013-05-30 12:40 ` David Laight 0 siblings, 0 replies; 19+ messages in thread From: David Laight @ 2013-05-30 12:40 UTC (permalink / raw) To: Antonio Quartulli; +Cc: Ben Hutchings, David Miller, amwang, netdev, horms > > Except I copied the wrong format line :-( It should be: > > printf("%x %x %x %x %x %x %lx %lx %llx %llx\n", > > ALL_ONES(a), ALL_ONES(b), ALL_ONES(c), ALL_ONES(d), > > ALL_ONES(e), ALL_ONES(f), ALL_ONES(g), ALL_ONES(h), > > ALL_ONES(i), ALL_ONES(j)); > > Oh ok, I see the issue now. > > So the problem is that this value gets bigger than what the maximal > value for the type passed as argument is supposed to be. > > I think the issue is clear now and why a double cast is good. It is much clearer to just use 0xffff. Although a named #define constant is more appropriate for the code itself. David ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-30 12:12 ` David Laight 2013-05-30 12:22 ` David Laight @ 2013-05-30 12:23 ` Antonio Quartulli 1 sibling, 0 replies; 19+ messages in thread From: Antonio Quartulli @ 2013-05-30 12:23 UTC (permalink / raw) To: David Laight; +Cc: Ben Hutchings, David Miller, amwang, netdev, horms [-- Attachment #1: Type: text/plain, Size: 2556 bytes --] On Thu, May 30, 2013 at 01:12:15PM +0100, David Laight wrote: > > > > > > > I want to use something that will either break the build or > > > > > > > automatically work if the type changes again. > > > > > > > > > > > > > > So something like "X = (typeof(X)) ~0U;". > > > > > > > > > > > > I think you mean ~(typeof(X))0. > > > > > > > > > > Am I wrong or you should cast the value once again, like this: > > > > > > > > > > ((typeof(X))~(typeof(X))0) > > > > > > > > > > because the ~ operator will implicitly cast the argument to int (if I remember > > > > > correctly). > > > > > > > > It will promote to at least int, but that still results in the right > > > > value and doesn't provoke a warning. Try this test (with -Wall > > > > -Wextra): > > > > > > > > #include <stdio.h> > > > > > > > > #define ALL_ONES(v) (~(typeof(v))0) > > > > /* #define ALL_ONES(v) (typeof(v))~0U) */ > > > > > > > > int main(void) > > > > { > > > > char a = ALL_ONES(a); > > > > unsigned char b = ALL_ONES(b); > > > > short c = ALL_ONES(c); > > > > unsigned short d = ALL_ONES(d); > > > > int e = ALL_ONES(e); > > > > unsigned int f = ALL_ONES(f); > > > > long g = ALL_ONES(g); > > > > unsigned long h = ALL_ONES(h); > > > > long long i = ALL_ONES(i); > > > > unsigned long long j = ALL_ONES(j); > > > > > > > > printf("%hhx %hhx %hx %hx %x %x %lx %lx %llx %llx\n", > > > > a, b, c, d, e, f, g, h, i, j); > > > > return 0; > > > > } > > > > > > The printf format is masking the high bits for you. > > > If you change to: > > > printf("%x %x %x %x %x %x %lx %lx %llx %llx\n", ...) > > > you get different values. > > > To get the 'expected' values you need casts both sides of the ~ > > > > I tried with > > > > 19 printf("%x %x %x %x %x %x %lx %lx %llx %llx\n", > > > > but I still see all FF. > > > > Somewhere else we have some hidden conversion? > > Of course - we need to look at the value that ALL_ONES() > generates in an expression. So the test print needs to be: > printf("%hhx %hhx %hx %hx %x %x %lx %lx %llx %llx\n", > ALL_ONES(a), ALL_ONES(b), ALL_ONES(c), ALL_ONES(d), > ALL_ONES(e), ALL_ONES(f), ALL_ONES(g), ALL_ONES(h), > ALL_ONES(i), ALL_ONES(j)); > which then gives 0xffffffff for the first 4 entries. It gives all FF for every argument. So, I'm not understanding the problem..this is what Ben wanted to achieve, no? Cheers, -- Antonio Quartulli ..each of us alone is worth nothing.. Ernesto "Che" Guevara [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-29 19:34 ` Ben Hutchings 2013-05-29 19:44 ` Antonio Quartulli @ 2013-05-30 1:59 ` Cong Wang 2013-05-30 12:30 ` Sergei Shtylyov 2013-05-30 10:40 ` David Miller 2 siblings, 1 reply; 19+ messages in thread From: Cong Wang @ 2013-05-30 1:59 UTC (permalink / raw) To: Ben Hutchings; +Cc: David Miller, netdev, horms On Wed, 2013-05-29 at 20:34 +0100, Ben Hutchings wrote: > On Tue, 2013-05-28 at 23:36 -0700, David Miller wrote: > > > > So something like "X = (typeof(X)) ~0U;". > > I think you mean ~(typeof(X))0. > Good catch, I will change it to ~(typeof(X))0. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-30 1:59 ` Cong Wang @ 2013-05-30 12:30 ` Sergei Shtylyov 0 siblings, 0 replies; 19+ messages in thread From: Sergei Shtylyov @ 2013-05-30 12:30 UTC (permalink / raw) To: Cong Wang; +Cc: Ben Hutchings, David Miller, netdev, horms Hello. On 30-05-2013 5:59, Cong Wang wrote: >>> So something like "X = (typeof(X)) ~0U;". >> I think you mean ~(typeof(X))0. > Good catch, I doubt it. > I will change it to ~(typeof(X))0. Then (typeof(X))0 will be promoted to *int* before doing ~. WBR, Sergei ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-29 19:34 ` Ben Hutchings 2013-05-29 19:44 ` Antonio Quartulli 2013-05-30 1:59 ` Cong Wang @ 2013-05-30 10:40 ` David Miller 2013-05-30 14:11 ` Ben Hutchings 2 siblings, 1 reply; 19+ messages in thread From: David Miller @ 2013-05-30 10:40 UTC (permalink / raw) To: bhutchings; +Cc: amwang, netdev, horms From: Ben Hutchings <bhutchings@solarflare.com> Date: Wed, 29 May 2013 20:34:33 +0100 > On Tue, 2013-05-28 at 23:36 -0700, David Miller wrote: >> From: Cong Wang <amwang@redhat.com> >> Date: Wed, 29 May 2013 14:09:00 +0800 >> >> > commit 1a37e412a0225fcba5587 (net: Use 16bits for *_headers >> > fields of struct skbuff) converts skb->*_header to u16, >> > therefore 1) we could just use 0xFFFFF instead of (__u16) ~0U >> > 2) some #if NET_SKBUFF_DATA_USES_OFFSET is useless now. >> > >> > >> > Cc: David S. Miller <davem@davemloft.net> >> > Cc: Simon Horman <horms@verge.net.au> >> > Signed-off-by: Cong Wang <amwang@redhat.com> >> >> I want to use something that will either break the build or >> automatically work if the type changes again. >> >> So something like "X = (typeof(X)) ~0U;". > > I think you mean ~(typeof(X))0. Take a look at what that does for ~(u8)0. We had a bug fix in this are recently in ieee802154 if I remember correctly. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [Patch net-next] net: clean up skb headers code 2013-05-30 10:40 ` David Miller @ 2013-05-30 14:11 ` Ben Hutchings 0 siblings, 0 replies; 19+ messages in thread From: Ben Hutchings @ 2013-05-30 14:11 UTC (permalink / raw) To: David Miller; +Cc: amwang, netdev, horms On Thu, 2013-05-30 at 03:40 -0700, David Miller wrote: > From: Ben Hutchings <bhutchings@solarflare.com> > Date: Wed, 29 May 2013 20:34:33 +0100 > > > On Tue, 2013-05-28 at 23:36 -0700, David Miller wrote: > >> From: Cong Wang <amwang@redhat.com> > >> Date: Wed, 29 May 2013 14:09:00 +0800 > >> > >> > commit 1a37e412a0225fcba5587 (net: Use 16bits for *_headers > >> > fields of struct skbuff) converts skb->*_header to u16, > >> > therefore 1) we could just use 0xFFFFF instead of (__u16) ~0U > >> > 2) some #if NET_SKBUFF_DATA_USES_OFFSET is useless now. > >> > > >> > > >> > Cc: David S. Miller <davem@davemloft.net> > >> > Cc: Simon Horman <horms@verge.net.au> > >> > Signed-off-by: Cong Wang <amwang@redhat.com> > >> > >> I want to use something that will either break the build or > >> automatically work if the type changes again. > >> > >> So something like "X = (typeof(X)) ~0U;". > > > > I think you mean ~(typeof(X))0. > > Take a look at what that does for ~(u8)0. > > We had a bug fix in this are recently in ieee802154 if I remember > correctly. It's fine if you assign the result to X. The second cast is needed if you need the temporary value to have the type of X, but that's not needed here. (Of course it may be promoted as soon as you do anything other than assign to X...) Ben. -- 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
end of thread, other threads:[~2013-05-30 14:11 UTC | newest] Thread overview: 19+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-05-29 6:09 [Patch net-next] net: clean up skb headers code Cong Wang 2013-05-29 6:36 ` David Miller 2013-05-29 6:48 ` Cong Wang 2013-05-29 6:49 ` David Miller 2013-05-29 19:34 ` Ben Hutchings 2013-05-29 19:44 ` Antonio Quartulli 2013-05-29 21:02 ` Ben Hutchings 2013-05-30 8:59 ` Antonio Quartulli 2013-05-30 11:41 ` David Laight 2013-05-30 11:45 ` Antonio Quartulli 2013-05-30 12:12 ` David Laight 2013-05-30 12:22 ` David Laight 2013-05-30 12:24 ` Antonio Quartulli 2013-05-30 12:40 ` David Laight 2013-05-30 12:23 ` Antonio Quartulli 2013-05-30 1:59 ` Cong Wang 2013-05-30 12:30 ` Sergei Shtylyov 2013-05-30 10:40 ` David Miller 2013-05-30 14:11 ` Ben Hutchings
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).