Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: Don't enable decoding if BAR hasn't been assigned an address

Don't enable memory or I/O decoding if we haven't assigned or claimed the
BAR's resource.

If we enable decoding for a BAR that hasn't been assigned an address, we'll
likely cause bus conflicts. This declines to enable decoding for resources
with IORESOURCE_UNSET.

Note that drivers can use pci_enable_device_io() or pci_enable_device_mem()
if they only care about specific types of BARs. In that case, we don't
bother checking whether the corresponding resources are assigned or
claimed.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

+8 -2
+8 -2
drivers/pci/setup-res.c
··· 343 343 (!(r->flags & IORESOURCE_ROM_ENABLE))) 344 344 continue; 345 345 346 + if (r->flags & IORESOURCE_UNSET) { 347 + dev_err(&dev->dev, "can't enable device: BAR %d %pR not assigned\n", 348 + i, r); 349 + return -EINVAL; 350 + } 351 + 346 352 if (!r->parent) { 347 - dev_err(&dev->dev, "device not available " 348 - "(can't reserve %pR)\n", r); 353 + dev_err(&dev->dev, "can't enable device: BAR %d %pR not claimed\n", 354 + i, r); 349 355 return -EINVAL; 350 356 } 351 357