This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 3f78220e943 virtio/virtio-net.c: Take RX buffers used while 
re-enabling the callback.
3f78220e943 is described below

commit 3f78220e94304436cf506de4083cead6412f79e4
Author: raiden00pl <[email protected]>
AuthorDate: Mon Oct 12 14:12:23 2026 +0200

    virtio/virtio-net.c: Take RX buffers used while re-enabling the callback.
    
    virtio_net_recv() ignored the result of virtqueue_enable_cb(), so a
    buffer the device used just before the callback was enabled raised no
    interrupt and stayed in the ring until the next RX interrupt.  Take it
    right away instead.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: raiden00pl <[email protected]>
---
 drivers/virtio/virtio-net.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/virtio/virtio-net.c b/drivers/virtio/virtio-net.c
index e199dcfb7e1..257f64db70a 100644
--- a/drivers/virtio/virtio-net.c
+++ b/drivers/virtio/virtio-net.c
@@ -476,15 +476,21 @@ static netpkt_t *virtio_net_recv(FAR struct 
netdev_lowerhalf_s *dev)
     {
       /* If we have no buffer left, enable RX callback. */
 
-      virtqueue_enable_cb(vq);
-      spin_unlock_irqrestore(&priv->lock[VIRTIO_NET_RX], flags);
+      if (virtqueue_enable_cb(vq))
+        {
+          /* A buffer was received before the callback was enabled */
 
-      vrtinfo("get NULL buffer\n");
-      return NULL;
+          virtqueue_disable_cb(vq);
+          hdr = virtqueue_get_buffer(vq, &len, NULL);
+        }
     }
-  else
+
+  spin_unlock_irqrestore(&priv->lock[VIRTIO_NET_RX], flags);
+
+  if (hdr == NULL)
     {
-      spin_unlock_irqrestore(&priv->lock[VIRTIO_NET_RX], flags);
+      vrtinfo("get NULL buffer\n");
+      return NULL;
     }
 
   /* Set the received pkt length */

Reply via email to