vmd(8): Fix error handling in tx path.
authorjan <jan@openbsd.org>
Fri, 12 Jul 2024 14:34:08 +0000 (14:34 +0000)
committerjan <jan@openbsd.org>
Fri, 12 Jul 2024 14:34:08 +0000 (14:34 +0000)
ok dv@

usr.sbin/vmd/vionet.c

index 4e4e2d9..8a82e30 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vionet.c,v 1.15 2024/07/09 18:49:05 jan Exp $ */
+/*     $OpenBSD: vionet.c,v 1.16 2024/07/12 14:34:08 jan Exp $ */
 
 /*
  * Copyright (c) 2023 Dave Voutila <dv@openbsd.org>
@@ -805,10 +805,8 @@ vionet_tx(struct virtio_dev *dev)
                }
 
                /* Check if we've got a minimum viable amount of data. */
-               if (chain_len < VIONET_MIN_TXLEN) {
-                       sz = chain_len;
+               if (chain_len < VIONET_MIN_TXLEN)
                        goto drop;
-               }
 
                /*
                 * Packet inspection for ethernet header (if using a "local"
@@ -832,7 +830,6 @@ vionet_tx(struct virtio_dev *dev)
                                log_warnx("%s: bad source address %s",
                                    __func__, ether_ntoa((struct ether_addr *)
                                        eh->ether_shost));
-                               sz = chain_len;
                                goto drop;
                        }
                }
@@ -852,10 +849,10 @@ vionet_tx(struct virtio_dev *dev)
                        log_warn("%s", __func__);
                        goto reset;
                }
-               sz += sizeof(struct virtio_net_hdr);
+               chain_len += sizeof(struct virtio_net_hdr);
 drop:
                used->ring[used->idx & VIONET_QUEUE_MASK].id = hdr_idx;
-               used->ring[used->idx & VIONET_QUEUE_MASK].len = sz;
+               used->ring[used->idx & VIONET_QUEUE_MASK].len = chain_len;
                __sync_synchronize();
                used->idx++;
                idx++;