From: kettenis Date: Sun, 11 Apr 2021 15:30:51 +0000 (+0000) Subject: On systems that hide the PCI bridge device corresponding to a PCIe RC port X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b699e85794e12d4fd991ee9a19cfb69c8386743c;p=openbsd On systems that hide the PCI bridge device corresponding to a PCIe RC port we may end up passing a NULL pointer to pcie_get_speed_cap(). Handle this by returning PCI_SPEED_UNKNOWN instead of dereferencing a null-pointer. ok jsg@ --- diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c index 1fc4db15c86..e478bbdeff6 100644 --- a/sys/dev/pci/drm/drm_linux.c +++ b/sys/dev/pci/drm/drm_linux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_linux.c,v 1.78 2021/02/14 03:42:55 jsg Exp $ */ +/* $OpenBSD: drm_linux.c,v 1.79 2021/04/11 15:30:51 kettenis Exp $ */ /* * Copyright (c) 2013 Jonathan Gray * Copyright (c) 2015, 2016 Mark Kettenis @@ -1760,14 +1760,20 @@ get_dma_buf(struct dma_buf *dmabuf) enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *pdev) { - pci_chipset_tag_t pc = pdev->pc; - pcitag_t tag = pdev->tag; + pci_chipset_tag_t pc; + pcitag_t tag; int pos ; pcireg_t xcap, lnkcap = 0, lnkcap2 = 0; pcireg_t id; enum pci_bus_speed cap = PCI_SPEED_UNKNOWN; int bus, device, function; + if (pdev == NULL) + return PCI_SPEED_UNKNOWN; + + pc = pdev->pc; + tag = pdev->tag; + if (!pci_get_capability(pc, tag, PCI_CAP_PCIEXPRESS, &pos, NULL)) return PCI_SPEED_UNKNOWN;