Re: [PATCH] PCI: stop crashing in pci_release_resource v2

From: Bjorn Helgaas
Date: Mon Feb 26 2018 - 15:56:40 EST


On Wed, Feb 21, 2018 at 10:07:15AM +0100, Christian König wrote:
> Is it 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.
>
> v2: keep printing the info that we try to release the BAR
>
> Signed-off-by: Christian König <christian.koenig@xxxxxxx>
> CC: stable@xxxxxxxxxxxxxxx

I think we probably want this in v4.16, since it seems to be a fix for
8bb705e3e79d ("PCI: Add pci_resize_resource() for resizing BARs"),
which appeared in v4.15.

What does the crash look like? I might include a few lines in the
changelog to help people find the fix.

I added a Fixes: tag and Andy's Reviewed-by already.

> ---
> drivers/pci/setup-res.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
> index e815111f3f81..c0f091614805 100644
> --- a/drivers/pci/setup-res.c
> +++ b/drivers/pci/setup-res.c
> @@ -402,6 +402,10 @@ void pci_release_resource(struct pci_dev *dev, int resno)
> struct resource *res = dev->resource + resno;
>
> dev_info(&dev->dev, "BAR %d: releasing %pR\n", resno, res);
> +
> + if (!res->parent)
> + return;
> +
> release_resource(res);
> res->end = resource_size(res) - 1;
> res->start = 0;
> --
> 2.14.1
>