PCI: Fail pci_ioremap_bar() on unassigned resources
Make pci_ioremap_bar() fail if we're trying to map a BAR that hasn't been
assigned.
Normally pci_enable_device() will fail if a BAR hasn't been assigned, but a
driver can successfully call pci_enable_device_io() even if a memory BAR
hasn't been assigned. That driver should not be able to use
pci_ioremap_bar() to map that unassigned memory BAR.
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index a6d191a..28df200 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -131,7 +131,7 @@
/*
* Make sure the BAR is actually a memory resource, not an IO resource
*/
- if (!(res->flags & IORESOURCE_MEM)) {
+ if (res->flags & IORESOURCE_UNSET || !(res->flags & IORESOURCE_MEM)) {
dev_warn(&pdev->dev, "can't ioremap BAR %d: %pR\n", bar, res);
return NULL;
}