pci_probe_device: make sure PCI_ID_REG returns valid data before touching

any other registers
This commit is contained in:
jmcneill 2020-02-02 16:30:31 +00:00
parent 21e52a637c
commit 57cc42dc03

View File

@ -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, pcitag_t tag,
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, pcitag_t tag,
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));