Skip to content

Commit 14bbd6a

Browse files
Pravin B Shelardavem330
authored andcommitted
net: Add skb_unclone() helper function.
This function will be used in next GRE_GSO patch. This patch does not change any functionality. Signed-off-by: Pravin B Shelar <[email protected]> Acked-by: Eric Dumazet <[email protected]>
1 parent d887199 commit 14bbd6a

File tree

13 files changed

+23
-21
lines changed

13 files changed

+23
-21
lines changed

drivers/net/ppp/ppp_generic.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,8 +1805,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
18051805
/* the filter instructions are constructed assuming
18061806
a four-byte PPP header on each packet */
18071807
if (ppp->pass_filter || ppp->active_filter) {
1808-
if (skb_cloned(skb) &&
1809-
pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
1808+
if (skb_unclone(skb, GFP_ATOMIC))
18101809
goto err;
18111810

18121811
*skb_push(skb, 2) = 0;

include/linux/skbuff.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,16 @@ static inline int skb_cloned(const struct sk_buff *skb)
804804
(atomic_read(&skb_shinfo(skb)->dataref) & SKB_DATAREF_MASK) != 1;
805805
}
806806

807+
static inline int skb_unclone(struct sk_buff *skb, gfp_t pri)
808+
{
809+
might_sleep_if(pri & __GFP_WAIT);
810+
811+
if (skb_cloned(skb))
812+
return pskb_expand_head(skb, 0, 0, pri);
813+
814+
return 0;
815+
}
816+
807817
/**
808818
* skb_header_cloned - is the header a clone
809819
* @skb: buffer to check

net/ipv4/ah4.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
321321

322322
/* We are going to _remove_ AH header to keep sockets happy,
323323
* so... Later this can change. */
324-
if (skb_cloned(skb) &&
325-
pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
324+
if (skb_unclone(skb, GFP_ATOMIC))
326325
goto out;
327326

328327
skb->ip_summed = CHECKSUM_NONE;

net/ipv4/ip_fragment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev,
590590
goto out_oversize;
591591

592592
/* Head of list must not be cloned. */
593-
if (skb_cloned(head) && pskb_expand_head(head, 0, 0, GFP_ATOMIC))
593+
if (skb_unclone(head, GFP_ATOMIC))
594594
goto out_nomem;
595595

596596
/* If the first fragment is fragmented itself, we split

net/ipv4/tcp_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ static void __pskb_trim_head(struct sk_buff *skb, int len)
13311331
/* Remove acked data from a packet in the transmit queue. */
13321332
int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len)
13331333
{
1334-
if (skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
1334+
if (skb_unclone(skb, GFP_ATOMIC))
13351335
return -ENOMEM;
13361336

13371337
__pskb_trim_head(skb, len);

net/ipv4/xfrm4_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int xfrm4_udp_encap_rcv(struct sock *sk, struct sk_buff *skb)
132132
* header and optional ESP marker bytes) and then modify the
133133
* protocol to ESP, and then call into the transform receiver.
134134
*/
135-
if (skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
135+
if (skb_unclone(skb, GFP_ATOMIC))
136136
goto drop;
137137

138138
/* Now we can update and verify the packet length... */

net/ipv4/xfrm4_mode_tunnel.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ static int xfrm4_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
142142
for_each_input_rcu(rcv_notify_handlers, handler)
143143
handler->handler(skb);
144144

145-
if (skb_cloned(skb) &&
146-
(err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))
145+
if (err = skb_unclone(skb, GFP_ATOMIC))
147146
goto out;
148147

149148
if (x->props.flags & XFRM_STATE_DECAP_DSCP)

net/ipv6/ah6.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,7 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
521521

522522
/* We are going to _remove_ AH header to keep sockets happy,
523523
* so... Later this can change. */
524-
if (skb_cloned(skb) &&
525-
pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
524+
if (skb_unclone(skb, GFP_ATOMIC))
526525
goto out;
527526

528527
skb->ip_summed = CHECKSUM_NONE;

net/ipv6/netfilter/nf_conntrack_reasm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ nf_ct_frag6_reasm(struct frag_queue *fq, struct net_device *dev)
368368
}
369369

370370
/* Head of list must not be cloned. */
371-
if (skb_cloned(head) && pskb_expand_head(head, 0, 0, GFP_ATOMIC)) {
371+
if (skb_unclone(head, GFP_ATOMIC)) {
372372
pr_debug("skb is cloned but can't expand head");
373373
goto out_oom;
374374
}

net/ipv6/reassembly.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
404404
goto out_oversize;
405405

406406
/* Head of list must not be cloned. */
407-
if (skb_cloned(head) && pskb_expand_head(head, 0, 0, GFP_ATOMIC))
407+
if (skb_unclone(head, GFP_ATOMIC))
408408
goto out_oom;
409409

410410
/* If the first fragment is fragmented itself, we split

net/ipv6/xfrm6_mode_tunnel.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ static int xfrm6_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
6969
if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
7070
goto out;
7171

72-
if (skb_cloned(skb) &&
73-
(err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))
72+
if (err = skb_unclone(skb, GFP_ATOMIC))
7473
goto out;
7574

7675
if (x->props.flags & XFRM_STATE_DECAP_DSCP)

net/sched/act_ipt.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,8 @@ static int tcf_ipt(struct sk_buff *skb, const struct tc_action *a,
207207
struct tcf_ipt *ipt = a->priv;
208208
struct xt_action_param par;
209209

210-
if (skb_cloned(skb)) {
211-
if (pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
212-
return TC_ACT_UNSPEC;
213-
}
210+
if (skb_unclone(skb, GFP_ATOMIC))
211+
return TC_ACT_UNSPEC;
214212

215213
spin_lock(&ipt->tcf_lock);
216214

net/sched/act_pedit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
131131
int i, munged = 0;
132132
unsigned int off;
133133

134-
if (skb_cloned(skb) &&
135-
pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
134+
if (skb_unclone(skb, GFP_ATOMIC))
136135
return p->tcf_action;
137136

138137
off = skb_network_offset(skb);

0 commit comments

Comments
 (0)