Skip to content

Commit b34ab35

Browse files
Radu Pirea (NXP OSS)davem330
authored andcommitted
net: macsec: use skb_ensure_writable_head_tail to expand the skb
Use skb_ensure_writable_head_tail to expand the skb if needed instead of reimplementing a similar operation. Signed-off-by: Radu Pirea (NXP OSS) <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 90abde4 commit b34ab35

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

drivers/net/macsec.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -604,26 +604,11 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
604604
return ERR_PTR(-EINVAL);
605605
}
606606

607-
if (unlikely(skb_headroom(skb) < MACSEC_NEEDED_HEADROOM ||
608-
skb_tailroom(skb) < MACSEC_NEEDED_TAILROOM)) {
609-
struct sk_buff *nskb = skb_copy_expand(skb,
610-
MACSEC_NEEDED_HEADROOM,
611-
MACSEC_NEEDED_TAILROOM,
612-
GFP_ATOMIC);
613-
if (likely(nskb)) {
614-
consume_skb(skb);
615-
skb = nskb;
616-
} else {
617-
macsec_txsa_put(tx_sa);
618-
kfree_skb(skb);
619-
return ERR_PTR(-ENOMEM);
620-
}
621-
} else {
622-
skb = skb_unshare(skb, GFP_ATOMIC);
623-
if (!skb) {
624-
macsec_txsa_put(tx_sa);
625-
return ERR_PTR(-ENOMEM);
626-
}
607+
ret = skb_ensure_writable_head_tail(skb, dev);
608+
if (unlikely(ret < 0)) {
609+
macsec_txsa_put(tx_sa);
610+
kfree_skb(skb);
611+
return ERR_PTR(ret);
627612
}
628613

629614
unprotected_len = skb->len;

0 commit comments

Comments
 (0)