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 indexing bug in clean up code on error in vi...



details:   https://anonhg.NetBSD.org/src/rev/5f24164813b4
branches:  trunk
changeset: 980191:5f24164813b4
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Tue Jan 26 16:40:16 2021 +0000

description:
Fix indexing bug in clean up code on error in virtio PCI v1.0 attach code.
Thanks go to Rin Okuyama for spotting it.

diffstat:

 sys/dev/pci/virtio_pci.c |  14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diffs (50 lines):

diff -r fb0ab7d7073e -r 5f24164813b4 sys/dev/pci/virtio_pci.c
--- a/sys/dev/pci/virtio_pci.c  Tue Jan 26 16:24:17 2021 +0000
+++ b/sys/dev/pci/virtio_pci.c  Tue Jan 26 16:40:16 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.25 2021/01/24 15:59:35 reinoud Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.26 2021/01/26 16:40:16 reinoud Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.25 2021/01/24 15:59:35 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.26 2021/01/26 16:40:16 reinoud Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -444,7 +444,7 @@
        bus_size_t bars[NMAPREG] = { 0 };
        int bars_idx[NMAPREG] = { 0 };
        struct virtio_pci_cap *caps[] = { &common, &isr, &device, &notify.cap };
-       int i, j = 0, ret = 0;
+       int i, j, ret = 0;
 
        if (virtio_pci_find_cap(psc, VIRTIO_PCI_CAP_COMMON_CFG,
                        &common, sizeof(common)))
@@ -471,7 +471,7 @@
                        bars[bar] = len;
        }
 
-       for (i = 0; i < __arraycount(bars); i++) {
+       for (i = j = 0; i < __arraycount(bars); i++) {
                int reg;
                pcireg_t type;
                if (bars[i] == 0)
@@ -551,10 +551,10 @@
 err:
        /* undo our pci_mapreg_map()s */ 
        for (i = 0; i < __arraycount(bars); i++) {
-               if (bars[i] == 0)
+               if (psc->sc_bars_iosize[i] == 0)
                        continue;
-               bus_space_unmap(psc->sc_bars_iot[j], psc->sc_bars_ioh[j],
-                               psc->sc_bars_iosize[j]);
+               bus_space_unmap(psc->sc_bars_iot[i], psc->sc_bars_ioh[i],
+                               psc->sc_bars_iosize[i]);
        }
        return ret;
 }



Home | Main Index | Thread Index | Old Index