Skip to contentSkip to conversation

tap-win32: correctly recycle buffers

PATCH In review Jason Wang 2 participants 3 messages Mar 29, 2021 – Apr 1, 2021 Networking

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 tap-win32: correctly recycle buffers

Commit 969e50b61a28 ("net: Pad short frames to minimum size before sending from SLiRP/TAP") tries to pad frames but try to recyle the local array that is used for padding to tap thread. This patch fixes this by recyling the original buffer.

Fixes 969e50b61a28 ("net: Pad short frames to minimum size before sending from SLiRP/TAP")
---
 net/tap-win32.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/tap-win32.c +4 -2
index d7c2a8759c..7a6f3d7384 100644
@@ -686,7 +686,7 @@ static ssize_t tap_receive(NetClientState *nc, const uint8_t *buf, size_t size)
 static void tap_win32_send(void *opaque)
 {
     TAPState *s = opaque;
-    uint8_t *buf;
+    uint8_t *buf, *orig_buf;
     int max_size = 4096;
     int size;
     uint8_t min_pkt[ETH_ZLEN];
@@ -694,6 +694,8 @@ static void tap_win32_send(void *opaque)
 
     size = tap_win32_read(s->handle, &buf, max_size);
     if (size > 0) {
+        orig_buf = buf;
+
         if (!s->nc.peer->do_not_pad) {
             if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
                 buf = min_pkt;
@@ -702,7 +704,7 @@ static void tap_win32_send(void *opaque)
         }
 
         qemu_send_packet(&s->nc, buf, size);
-        tap_win32_free_buffer(s->handle, buf);
+        tap_win32_free_buffer(s->handle, orig_buf);
     }
 }
 
Signature · 1 line
2.24.3 (Apple Git-128)
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jason Wang

Commit 969e50b61a28 ("net: Pad short frames to minimum size before sending from SLiRP/TAP") tries to pad frames but try to recyle the local array that is used for padding to tap thread. This patch fixes this by recyling the original buffer.

Quoted 7 lines
Fixes 969e50b61a28 ("net: Pad short frames to minimum size before sending from SLiRP/TAP")
---
 net/tap-win32.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Tested booting U-Boot with QEMU ppce500 on Windows, without the patch, QEMU crashes

author Applied
#2 lore raw
Quoted 13 lines · Bin Meng
Quoted 5 lines · Jason Wang

Commit 969e50b61a28 ("net: Pad short frames to minimum size before sending from SLiRP/TAP") tries to pad frames but try to recyle the local array that is used for padding to tap thread. This patch fixes this by recyling the original buffer.

Quoted 7 lines
Fixes 969e50b61a28 ("net: Pad short frames to minimum size before sending from SLiRP/TAP")
---
  net/tap-win32.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 6 lines

Tested booting U-Boot with QEMU ppce500 on Windows, without the patch, QEMU crashes

Applied.

Thanks