Skip to content

Commit 35d0461

Browse files
Cong Wangdavem330
authored andcommitted
net: clean up skb headers code
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 <[email protected]> Cc: Simon Horman <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 938177e commit 35d0461

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

include/linux/skbuff.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,7 @@ static inline void skb_set_inner_mac_header(struct sk_buff *skb,
15931593
}
15941594
static inline bool skb_transport_header_was_set(const struct sk_buff *skb)
15951595
{
1596-
return skb->transport_header != ~0U;
1596+
return skb->transport_header != (typeof(skb->transport_header))~0U;
15971597
}
15981598

15991599
static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
@@ -1636,7 +1636,7 @@ static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
16361636

16371637
static inline int skb_mac_header_was_set(const struct sk_buff *skb)
16381638
{
1639-
return skb->mac_header != ~0U;
1639+
return skb->mac_header != (typeof(skb->mac_header))~0U;
16401640
}
16411641

16421642
static inline void skb_reset_mac_header(struct sk_buff *skb)

net/core/skbuff.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ struct sk_buff *__alloc_skb_head(gfp_t gfp_mask, int node)
199199
skb->truesize = sizeof(struct sk_buff);
200200
atomic_set(&skb->users, 1);
201201

202-
#ifdef NET_SKBUFF_DATA_USES_OFFSET
203-
skb->mac_header = (__u16) ~0U;
204-
#endif
202+
skb->mac_header = (typeof(skb->mac_header))~0U;
205203
out:
206204
return skb;
207205
}
@@ -275,10 +273,8 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
275273
skb->data = data;
276274
skb_reset_tail_pointer(skb);
277275
skb->end = skb->tail + size;
278-
#ifdef NET_SKBUFF_DATA_USES_OFFSET
279-
skb->mac_header = (__u16) ~0U;
280-
skb->transport_header = (__u16) ~0U;
281-
#endif
276+
skb->mac_header = (typeof(skb->mac_header))~0U;
277+
skb->transport_header = (typeof(skb->transport_header))~0U;
282278

283279
/* make sure we initialize shinfo sequentially */
284280
shinfo = skb_shinfo(skb);
@@ -344,10 +340,8 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size)
344340
skb->data = data;
345341
skb_reset_tail_pointer(skb);
346342
skb->end = skb->tail + size;
347-
#ifdef NET_SKBUFF_DATA_USES_OFFSET
348-
skb->mac_header = (__u16) ~0U;
349-
skb->transport_header = (__u16) ~0U;
350-
#endif
343+
skb->mac_header = (typeof(skb->mac_header))~0U;
344+
skb->transport_header = (typeof(skb->transport_header))~0U;
351345

352346
/* make sure we initialize shinfo sequentially */
353347
shinfo = skb_shinfo(skb);

0 commit comments

Comments
 (0)