diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 966af3beed94..ab195b99c853 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -7236,16 +7236,23 @@ static void skb_ext_put_sp(struct sec_path *sp) { unsigned int i; + if (!sp->len) + return; + for (i = 0; i < sp->len; i++) xfrm_state_put(sp->xvec[i]); + sp->len = 0; } #endif #ifdef CONFIG_MCTP_FLOWS static void skb_ext_put_mctp(struct mctp_flow *flow) { - if (flow->key) - mctp_key_unref(flow->key); + if (!flow->key) + return; + + mctp_key_unref(flow->key); + flow->key = NULL; } #endif @@ -7257,15 +7264,20 @@ void __skb_ext_del(struct sk_buff *skb, enum skb_ext_id id) if (skb->active_extensions == 0) { skb->extensions = NULL; __skb_ext_put(ext); -#ifdef CONFIG_XFRM - } else if (id == SKB_EXT_SEC_PATH && - refcount_read(&ext->refcnt) == 1) { - struct sec_path *sp = skb_ext_get_ptr(ext, SKB_EXT_SEC_PATH); - - skb_ext_put_sp(sp); - sp->len = 0; -#endif + return; } + + if (refcount_read(&ext->refcnt) > 1) + return; + +#ifdef CONFIG_XFRM + if (id == SKB_EXT_SEC_PATH) + skb_ext_put_sp(skb_ext_get_ptr(ext, SKB_EXT_SEC_PATH)); +#endif +#ifdef CONFIG_MCTP_FLOWS + if (id == SKB_EXT_MCTP) + skb_ext_put_mctp(skb_ext_get_ptr(ext, SKB_EXT_MCTP)); +#endif } EXPORT_SYMBOL(__skb_ext_del);