virtio_net: free xdp shinfo frags when build_skb_from_xdp_buff() fails
authorXuan Zhuo <xuanzhuo@linux.alibaba.com>
Wed, 15 Mar 2023 01:52:23 +0000 (09:52 +0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 16 Mar 2023 17:46:05 +0000 (17:46 +0000)
build_skb_from_xdp_buff() may return NULL, in this case
we need to free the frags of xdp shinfo.

Fixes: fab89bafa95b ("virtio-net: support multi-buffer xdp")
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/virtio_net.c

index 8ecf7a341d5437437a9ee307ae4b242c732914e1..2396c28c01221956c12d6b1611efc020ac76547d 100644 (file)
@@ -1273,9 +1273,12 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 
                switch (act) {
                case XDP_PASS:
+                       head_skb = build_skb_from_xdp_buff(dev, vi, &xdp, xdp_frags_truesz);
+                       if (unlikely(!head_skb))
+                               goto err_xdp_frags;
+
                        if (unlikely(xdp_page != page))
                                put_page(page);
-                       head_skb = build_skb_from_xdp_buff(dev, vi, &xdp, xdp_frags_truesz);
                        rcu_read_unlock();
                        return head_skb;
                case XDP_TX: