Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci pci_probe_device: make sure PCI_ID_REG returns v...



details:   https://anonhg.NetBSD.org/src/rev/3805b06c9263
branches:  trunk
changeset: 968968:3805b06c9263
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Feb 02 16:30:31 2020 +0000

description:
pci_probe_device: make sure PCI_ID_REG returns valid data before touching
any other registers

diffstat:

 sys/dev/pci/pci.c |  17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diffs (46 lines):

diff -r b2096c5905ab -r 3805b06c9263 sys/dev/pci/pci.c
--- a/sys/dev/pci/pci.c Sun Feb 02 14:45:14 2020 +0000
+++ b/sys/dev/pci/pci.c Sun Feb 02 16:30:31 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci.c,v 1.156 2019/10/15 13:27:11 jmcneill Exp $       */
+/*     $NetBSD: pci.c,v 1.157 2020/02/02 16:30:31 jmcneill Exp $       */
 
 /*
  * Copyright (c) 1995, 1996, 1997, 1998
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.156 2019/10/15 13:27:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.157 2020/02/02 16:30:31 jmcneill Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pci.h"
@@ -288,13 +288,7 @@
        if (sc->PCI_SC_DEVICESC(device, function).c_dev != NULL && !match)
                return 0;
 
-       bhlcr = pci_conf_read(pc, tag, PCI_BHLC_REG);
-       if (PCI_HDRTYPE_TYPE(bhlcr) > 2)
-               return 0;
-
        id = pci_conf_read(pc, tag, PCI_ID_REG);
-       /* csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG); */
-       pciclass = pci_conf_read(pc, tag, PCI_CLASS_REG);
 
        /* Invalid vendor ID value? */
        if (PCI_VENDOR(id) == PCI_VENDOR_INVALID)
@@ -303,6 +297,13 @@
        if (PCI_VENDOR(id) == 0)
                return 0;
 
+       bhlcr = pci_conf_read(pc, tag, PCI_BHLC_REG);
+       if (PCI_HDRTYPE_TYPE(bhlcr) > 2)
+               return 0;
+
+       /* csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG); */
+       pciclass = pci_conf_read(pc, tag, PCI_CLASS_REG);
+
        /* Collect memory range info */
        memset(sc->PCI_SC_DEVICESC(device, function).c_range, 0,
            sizeof(sc->PCI_SC_DEVICESC(device, function).c_range));



Home | Main Index | Thread Index | Old Index