Commit d427c899 authored by Richard Gobert's avatar Richard Gobert Committed by David S. Miller

net-next: skbuff: refactor pskb_pull

pskb_may_pull already contains all of the checks performed by
pskb_pull.
Use pskb_may_pull for validation in pskb_pull, eliminating the
duplication and making __pskb_pull obsolete.
Replace __pskb_pull with pskb_pull where applicable.
Signed-off-by: default avatarRichard Gobert <richardbgobert@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 96e07181
...@@ -2616,20 +2616,6 @@ void *skb_pull_data(struct sk_buff *skb, size_t len); ...@@ -2616,20 +2616,6 @@ void *skb_pull_data(struct sk_buff *skb, size_t len);
void *__pskb_pull_tail(struct sk_buff *skb, int delta); void *__pskb_pull_tail(struct sk_buff *skb, int delta);
static inline void *__pskb_pull(struct sk_buff *skb, unsigned int len)
{
if (len > skb_headlen(skb) &&
!__pskb_pull_tail(skb, len - skb_headlen(skb)))
return NULL;
skb->len -= len;
return skb->data += len;
}
static inline void *pskb_pull(struct sk_buff *skb, unsigned int len)
{
return unlikely(len > skb->len) ? NULL : __pskb_pull(skb, len);
}
static inline bool pskb_may_pull(struct sk_buff *skb, unsigned int len) static inline bool pskb_may_pull(struct sk_buff *skb, unsigned int len)
{ {
if (likely(len <= skb_headlen(skb))) if (likely(len <= skb_headlen(skb)))
...@@ -2639,6 +2625,15 @@ static inline bool pskb_may_pull(struct sk_buff *skb, unsigned int len) ...@@ -2639,6 +2625,15 @@ static inline bool pskb_may_pull(struct sk_buff *skb, unsigned int len)
return __pskb_pull_tail(skb, len - skb_headlen(skb)) != NULL; return __pskb_pull_tail(skb, len - skb_headlen(skb)) != NULL;
} }
static inline void *pskb_pull(struct sk_buff *skb, unsigned int len)
{
if (!pskb_may_pull(skb, len))
return NULL;
skb->len -= len;
return skb->data += len;
}
void skb_condense(struct sk_buff *skb); void skb_condense(struct sk_buff *skb);
/** /**
......
...@@ -232,7 +232,7 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head, ...@@ -232,7 +232,7 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head,
proto = iph->nexthdr; proto = iph->nexthdr;
ops = rcu_dereference(inet6_offloads[proto]); ops = rcu_dereference(inet6_offloads[proto]);
if (!ops || !ops->callbacks.gro_receive) { if (!ops || !ops->callbacks.gro_receive) {
__pskb_pull(skb, skb_gro_offset(skb)); pskb_pull(skb, skb_gro_offset(skb));
skb_gro_frag0_invalidate(skb); skb_gro_frag0_invalidate(skb);
proto = ipv6_gso_pull_exthdrs(skb, proto); proto = ipv6_gso_pull_exthdrs(skb, proto);
skb_gro_pull(skb, -skb_transport_offset(skb)); skb_gro_pull(skb, -skb_transport_offset(skb));
......
...@@ -49,7 +49,7 @@ static struct sk_buff *ieee80211_clean_skb(struct sk_buff *skb, ...@@ -49,7 +49,7 @@ static struct sk_buff *ieee80211_clean_skb(struct sk_buff *skb,
if (present_fcs_len) if (present_fcs_len)
__pskb_trim(skb, skb->len - present_fcs_len); __pskb_trim(skb, skb->len - present_fcs_len);
__pskb_pull(skb, rtap_space); pskb_pull(skb, rtap_space);
hdr = (void *)skb->data; hdr = (void *)skb->data;
fc = hdr->frame_control; fc = hdr->frame_control;
...@@ -74,7 +74,7 @@ static struct sk_buff *ieee80211_clean_skb(struct sk_buff *skb, ...@@ -74,7 +74,7 @@ static struct sk_buff *ieee80211_clean_skb(struct sk_buff *skb,
memmove(skb->data + IEEE80211_HT_CTL_LEN, skb->data, memmove(skb->data + IEEE80211_HT_CTL_LEN, skb->data,
hdrlen - IEEE80211_HT_CTL_LEN); hdrlen - IEEE80211_HT_CTL_LEN);
__pskb_pull(skb, IEEE80211_HT_CTL_LEN); pskb_pull(skb, IEEE80211_HT_CTL_LEN);
return skb; return skb;
} }
......
...@@ -91,7 +91,7 @@ static void espintcp_rcv(struct strparser *strp, struct sk_buff *skb) ...@@ -91,7 +91,7 @@ static void espintcp_rcv(struct strparser *strp, struct sk_buff *skb)
} }
/* remove header, leave non-ESP marker/SPI */ /* remove header, leave non-ESP marker/SPI */
if (!__pskb_pull(skb, rxm->offset + 2)) { if (!pskb_pull(skb, rxm->offset + 2)) {
XFRM_INC_STATS(sock_net(strp->sk), LINUX_MIB_XFRMINERROR); XFRM_INC_STATS(sock_net(strp->sk), LINUX_MIB_XFRMINERROR);
kfree_skb(skb); kfree_skb(skb);
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment