diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index fd7472f286742b729441f9d1e08223beed6a8200..dcda5212f3bb9b2540ff04bc6b8ef8e1a8e4f0f5 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -485,7 +485,8 @@ static struct intel_iommu *device_to_iommu(int segment, u8 bus, u8 devfn)
 			    drhd->devices[i]->bus->number == bus &&
 			    drhd->devices[i]->devfn == devfn)
 				return drhd->iommu;
-			if (drhd->devices[i]->subordinate &&
+			if (drhd->devices[i] &&
+			    drhd->devices[i]->subordinate &&
 			    drhd->devices[i]->subordinate->number <= bus &&
 			    drhd->devices[i]->subordinate->subordinate >= bus)
 				return drhd->iommu;