virtio_net: separate the logic of freeing the rest mergeable buf
authorXuan Zhuo <xuanzhuo@linux.alibaba.com>
Mon, 8 May 2023 06:14:08 +0000 (14:14 +0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 10 May 2023 02:44:27 +0000 (19:44 -0700)
This patch introduce a new function that frees the rest mergeable buf.
The subsequent patch will reuse this function.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/virtio_net.c

index c1538ab467956b55f3b7fd8fde464b1aad8dc7da..b26e95c9614123538f6c0fbe5240defc2e405a3b 100644 (file)
@@ -1071,6 +1071,28 @@ err:
        return NULL;
 }
 
+static void mergeable_buf_free(struct receive_queue *rq, int num_buf,
+                              struct net_device *dev,
+                              struct virtnet_rq_stats *stats)
+{
+       struct page *page;
+       void *buf;
+       int len;
+
+       while (num_buf-- > 1) {
+               buf = virtqueue_get_buf(rq->vq, &len);
+               if (unlikely(!buf)) {
+                       pr_debug("%s: rx error: %d buffers missing\n",
+                                dev->name, num_buf);
+                       dev->stats.rx_length_errors++;
+                       break;
+               }
+               stats->bytes += len;
+               page = virt_to_head_page(buf);
+               put_page(page);
+       }
+}
+
 /* Why not use xdp_build_skb_from_frame() ?
  * XDP core assumes that xdp frags are PAGE_SIZE in length, while in
  * virtio-net there are 2 points that do not match its requirements:
@@ -1431,18 +1453,8 @@ err_xdp:
        stats->xdp_drops++;
 err_skb:
        put_page(page);
-       while (num_buf-- > 1) {
-               buf = virtqueue_get_buf(rq->vq, &len);
-               if (unlikely(!buf)) {
-                       pr_debug("%s: rx error: %d buffers missing\n",
-                                dev->name, num_buf);
-                       dev->stats.rx_length_errors++;
-                       break;
-               }
-               stats->bytes += len;
-               page = virt_to_head_page(buf);
-               put_page(page);
-       }
+       mergeable_buf_free(rq, num_buf, dev, stats);
+
 err_buf:
        stats->drops++;
        dev_kfree_skb(head_skb);