Module Name: src
Committed By: jmcneill
Date: Sun Feb 2 16:30:31 UTC 2020
Modified Files:
src/sys/dev/pci: pci.c
Log Message:
pci_probe_device: make sure PCI_ID_REG returns valid data before touching
any other registers
To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/sys/dev/pci/pci.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/pci/pci.c
diff -u src/sys/dev/pci/pci.c:1.156 src/sys/dev/pci/pci.c:1.157
--- src/sys/dev/pci/pci.c:1.156 Tue Oct 15 13:27:11 2019
+++ src/sys/dev/pci/pci.c Sun Feb 2 16:30:31 2020
@@ -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 @@ pci_probe_device(struct pci_softc *sc, p
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 @@ pci_probe_device(struct pci_softc *sc, p
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));