If mbuf refcnt was > 1 then rte_vlan_insert() would incorrectly modify the original copy. Original code was expecting clone to make a copy (it doesn't). Better to let the caller deal with making a copy or setting up mbuf chain to allow for header to be added.
Also fix docbook comment about parameters (function takes pointer to mbuf). Fixes: c974021a5949 ("ether: add soft vlan encap/decap") Signed-off-by: Stephen Hemminger <sthem...@microsoft.com> --- lib/librte_net/rte_ether.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index c2c5e249ffe9..bab2b198fa79 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -374,7 +374,7 @@ static inline int rte_vlan_strip(struct rte_mbuf *m) * Software version of VLAN unstripping * * @param m - * The packet mbuf. + * Pointer to the packet mbuf. * @return * - 0: On success * -EPERM: mbuf is is shared overwriting would be unsafe @@ -385,16 +385,9 @@ static inline int rte_vlan_insert(struct rte_mbuf **m) struct ether_hdr *oh, *nh; struct vlan_hdr *vh; - /* Can't insert header if mbuf is shared */ - if (rte_mbuf_refcnt_read(*m) > 1) { - struct rte_mbuf *copy; - - copy = rte_pktmbuf_clone(*m, (*m)->pool); - if (unlikely(copy == NULL)) - return -ENOMEM; - rte_pktmbuf_free(*m); - *m = copy; - } + /* Can't directly insert header if mbuf is shared */ + if (rte_mbuf_refcnt_read(*m) > 1) + return -EPERM; oh = rte_pktmbuf_mtod(*m, struct ether_hdr *); nh = (struct ether_hdr *) -- 2.17.1