PCI: Allow release of resources that were never assigned
authorChristian König <ckoenig.leichtzumerken@gmail.com>
Mon, 26 Feb 2018 20:51:13 +0000 (14:51 -0600)
committerBjorn Helgaas <helgaas@kernel.org>
Mon, 26 Feb 2018 20:51:13 +0000 (14:51 -0600)
It is entirely possible that the BIOS wasn't able to assign resources to a
device. In this case don't crash in pci_release_resource() when we try to
resize the resource.

Fixes: 8bb705e3e79d ("PCI: Add pci_resize_resource() for resizing BARs")
Signed-off-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
CC: stable@vger.kernel.org # v4.15+
drivers/pci/setup-res.c

index 369d48d..3654472 100644 (file)
@@ -401,6 +401,10 @@ void pci_release_resource(struct pci_dev *dev, int resno)
        struct resource *res = dev->resource + resno;
 
        pci_info(dev, "BAR %d: releasing %pR\n", resno, res);
+
+       if (!res->parent)
+               return;
+
        release_resource(res);
        res->end = resource_size(res) - 1;
        res->start = 0;