Skip to content

Commit

Permalink
net: clean up skb headers code
Browse files Browse the repository at this point in the history
commit 1a37e41 (net: Use 16bits for *_headers
fields of struct skbuff) converts skb->*_header to u16,
some #if NET_SKBUFF_DATA_USES_OFFSET are now useless,
and to be safe, we could just use "X = (typeof(X)) ~0U;"
as suggested by David.

Cc: David S. Miller <davem@davemloft.net>
Cc: Simon Horman <horms@verge.net.au>
Signed-off-by: Cong Wang <amwang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Cong Wang authored and David S. Miller committed Jun 1, 2013
1 parent 938177e commit 35d0461
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
4 changes: 2 additions & 2 deletions include/linux/skbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,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 != (typeof(skb->transport_header))~0U;
}

static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
Expand Down Expand Up @@ -1636,7 +1636,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 != (typeof(skb->mac_header))~0U;
}

static inline void skb_reset_mac_header(struct sk_buff *skb)
Expand Down
16 changes: 5 additions & 11 deletions net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (typeof(skb->mac_header))~0U;
out:
return skb;
}
Expand Down Expand Up @@ -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 = (typeof(skb->mac_header))~0U;
skb->transport_header = (typeof(skb->transport_header))~0U;

/* make sure we initialize shinfo sequentially */
shinfo = skb_shinfo(skb);
Expand Down Expand Up @@ -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 = (typeof(skb->mac_header))~0U;
skb->transport_header = (typeof(skb->transport_header))~0U;

/* make sure we initialize shinfo sequentially */
shinfo = skb_shinfo(skb);
Expand Down

0 comments on commit 35d0461

Please sign in to comment.