From 3c02da8096b142ef243da8da667c3a5a7d591105 Mon Sep 17 00:00:00 2001 From: Kornel Duleba Date: Thu, 21 Oct 2021 14:46:51 +0200 Subject: [PATCH] dmar: Don't try to reserve PCI regions for non-existing devices In some cases we might have to create DMAR context before the corresponding device has been enumerated by the PCI bus. In that case we get called with NULL dev, because of that trying to reserve PCI regions causes a NULL pointer dereference in pci_find_pcie_root_port. Sponsored by: Stormshield Obtained from: Semihalf MFC after: 2 weeks Reviewed by: kib, rlibby Differential revision: https://reviews.freebsd.org/D32589 --- sys/x86/iommu/intel_ctx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/x86/iommu/intel_ctx.c b/sys/x86/iommu/intel_ctx.c index 34730306000b..7aedbf159ac7 100644 --- a/sys/x86/iommu/intel_ctx.c +++ b/sys/x86/iommu/intel_ctx.c @@ -561,7 +561,7 @@ dmar_get_ctx_for_dev1(struct dmar_unit *dmar, device_t dev, uint16_t rid, error = domain_init_rmrr(domain1, dev, bus, slot, func, dev_domain, dev_busno, dev_path, dev_path_len); - if (error == 0) + if (error == 0 && dev != NULL) error = dmar_reserve_pci_regions(domain1, dev); if (error != 0) { dmar_domain_destroy(domain1);