Re: [PATCH] PCI: iproc: fix resource allocation for BCMA PCIe

From: Abylay Ospan
Date: Wed Feb 08 2017 - 17:31:25 EST

Hi Bjorn,

I have checked first listed driver
(drivers/pci/host/pcie-designware.c). Seems like into
'devm_request_pci_bus_resources' we supply same stack allocated 'res'
(actual insert of this pointer to 'iomem_resource' was done inside
'__request_resource'). This 'res' is not changed inside
I don't have this platforms on hand and cannot test it on real
hadrware (to 100% verify). But investigating this code I see that the
problem exist.

Here is a summary of flow for 'res' to show the problem:

ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &res,
&pp->io_base); <--- 'res' not changing here
ret = devm_request_pci_bus_resources(&pdev->dev, &res);

err = devm_request_resource(dev, parent, res);

conflict = request_resource_conflict(root, new);
conflict = __request_resource(root, new);
*p = new; <--- here we introduce stack allocated res into
global 'iomem_resource'

Please check and correct me if i'm wrong ?

> dw_pcie_host_init
> LIST_HEAD(res) # on stack
> of_pci_get_host_bridge_resources(np, 0, 0xff, &res, &pp->io_base)
> res = kzalloc() # different "res" from above!
> pci_add_resource_offset(resources, res, ...)
> devm_request_pci_bus_resources(&pdev->dev, &res)
> pci_scan_root_bus(pp->dev, pp->root_bus_nr, &dw_pcie_ops, pp, &res)
> error:
> pci_free_resource_list(&res)

> This looks good to me, but I don't think it's necessary to keep the
> list_head in the struct iproc_pcie. It should be safe to use
> "LIST_HEAD(res)" on the stack like the other drivers do. Can you
> verify that and get an ack from Ray, Scott, or Jon?

if my investigation above is true then we need to keep 'res' all the
time we working with the driver (or find another way to fix this

Abylay Ospan,
NetUP Inc.