Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Fix not to allocate unnecessary descriptor



details:   https://anonhg.NetBSD.org/src/rev/1ee9362c5a1a
branches:  trunk
changeset: 374331:1ee9362c5a1a
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Wed Apr 19 00:38:30 2023 +0000

description:
Fix not to allocate unnecessary descriptor

fixes PR/57358

diffstat:

 sys/dev/pci/virtio.c |  21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diffs (45 lines):

diff -r 425731fc2088 -r 1ee9362c5a1a sys/dev/pci/virtio.c
--- a/sys/dev/pci/virtio.c      Wed Apr 19 00:23:45 2023 +0000
+++ b/sys/dev/pci/virtio.c      Wed Apr 19 00:38:30 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: virtio.c,v 1.75 2023/04/19 00:23:45 yamaguchi Exp $    */
+/*     $NetBSD: virtio.c,v 1.76 2023/04/19 00:38:30 yamaguchi Exp $    */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.75 2023/04/19 00:23:45 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio.c,v 1.76 2023/04/19 00:38:30 yamaguchi Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1096,17 +1096,18 @@ virtio_enqueue_reserve(struct virtio_sof
                }
                vd[i].flags  = virtio_rw16(sc, 0);
        } else {
-               uint16_t s;
+               if (nsegs > 1) {
+                       uint16_t s;
 
-               s = vq_alloc_slot(sc, vq, nsegs - 1);
-               if (s == VRING_DESC_CHAIN_END) {
-                       vq_free_slot(sc, vq, slot);
-                       return EAGAIN;
+                       s = vq_alloc_slot(sc, vq, nsegs - 1);
+                       if (s == VRING_DESC_CHAIN_END) {
+                               vq_free_slot(sc, vq, slot);
+                               return EAGAIN;
+                       }
+                       vd->next = virtio_rw16(sc, s);
+                       vd->flags = virtio_rw16(sc, VRING_DESC_F_NEXT);
                }
 
-               vd->next = virtio_rw16(sc, s);
-               vd->flags = virtio_rw16(sc, VRING_DESC_F_NEXT);
-
                vdx->desc_base = &vq->vq_desc[0];
                vdx->desc_free_idx = slot;
        }



Home | Main Index | Thread Index | Old Index