mirror of
https://github.com/torvalds/linux.git
synced 2024-11-26 14:12:06 +00:00
PCI: Rework of_pci_get_host_bridge_resources() to devm_of_pci_get_host_bridge_resources()
of_pci_get_host_bridge_resources() allocates the resource structures it fills dynamically, but none of its callers care to release them so far. Rather than requiring everyone to do this explicitly, convert the existing function to a managed version. Tested-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com> Acked-by: Joao Pinto <jpinto@synopsys.com> Acked-by: Jingoo Han <jingoohan1@gmail.com> CC: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
This commit is contained in:
parent
d9c5d5ac28
commit
5bd51b35c7
@ -342,7 +342,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
|
|||||||
if (!bridge)
|
if (!bridge)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ret = of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
||||||
&bridge->windows, &pp->io_base);
|
&bridge->windows, &pp->io_base);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -820,7 +820,7 @@ static int advk_pcie_parse_request_of_pci_ranges(struct advk_pcie *pcie)
|
|||||||
|
|
||||||
INIT_LIST_HEAD(&pcie->resources);
|
INIT_LIST_HEAD(&pcie->resources);
|
||||||
|
|
||||||
err = of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
||||||
&pcie->resources, &iobase);
|
&pcie->resources, &iobase);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
@ -476,7 +476,7 @@ static int faraday_pci_probe(struct platform_device *pdev)
|
|||||||
if (IS_ERR(p->base))
|
if (IS_ERR(p->base))
|
||||||
return PTR_ERR(p->base);
|
return PTR_ERR(p->base);
|
||||||
|
|
||||||
ret = of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
||||||
&res, &io_base);
|
&res, &io_base);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -791,7 +791,7 @@ static int v3_pci_probe(struct platform_device *pdev)
|
|||||||
if (IS_ERR(v3->config_base))
|
if (IS_ERR(v3->config_base))
|
||||||
return PTR_ERR(v3->config_base);
|
return PTR_ERR(v3->config_base);
|
||||||
|
|
||||||
ret = of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
|
ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
|
||||||
&io_base);
|
&io_base);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -67,7 +67,7 @@ static int versatile_pci_parse_request_of_pci_ranges(struct device *dev,
|
|||||||
resource_size_t iobase;
|
resource_size_t iobase;
|
||||||
struct resource_entry *win, *tmp;
|
struct resource_entry *win, *tmp;
|
||||||
|
|
||||||
err = of_pci_get_host_bridge_resources(dev, 0, 0xff, res, &iobase);
|
err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, res, &iobase);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -632,7 +632,7 @@ static int xgene_pcie_probe(struct platform_device *pdev)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
|
ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
|
||||||
&iobase);
|
&iobase);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -490,7 +490,7 @@ static int altera_pcie_parse_request_of_pci_ranges(struct altera_pcie *pcie)
|
|||||||
struct device *dev = &pcie->pdev->dev;
|
struct device *dev = &pcie->pdev->dev;
|
||||||
struct resource_entry *win;
|
struct resource_entry *win;
|
||||||
|
|
||||||
err = of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
||||||
&pcie->resources, NULL);
|
&pcie->resources, NULL);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
@ -99,7 +99,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
|
|||||||
pcie->phy = NULL;
|
pcie->phy = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = of_pci_get_host_bridge_resources(dev, 0, 0xff, &resources,
|
ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &resources,
|
||||||
&iobase);
|
&iobase);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(dev, "unable to get PCI host bridge resources\n");
|
dev_err(dev, "unable to get PCI host bridge resources\n");
|
||||||
|
@ -1070,7 +1070,7 @@ static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci)
|
|||||||
resource_size_t iobase;
|
resource_size_t iobase;
|
||||||
struct resource_entry *win, *tmp;
|
struct resource_entry *win, *tmp;
|
||||||
|
|
||||||
err = of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
||||||
&pci->resources, &iobase);
|
&pci->resources, &iobase);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
@ -1560,7 +1560,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
|
|||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto err_deinit_port;
|
goto err_deinit_port;
|
||||||
|
|
||||||
err = of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
|
||||||
&res, &io_base);
|
&res, &io_base);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_remove_irq_domain;
|
goto err_remove_irq_domain;
|
||||||
|
@ -854,7 +854,7 @@ static int nwl_pcie_probe(struct platform_device *pdev)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
|
err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
|
||||||
&iobase);
|
&iobase);
|
||||||
if (err) {
|
if (err) {
|
||||||
dev_err(dev, "Getting bridge resources failed\n");
|
dev_err(dev, "Getting bridge resources failed\n");
|
||||||
|
@ -643,7 +643,7 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
|
err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &res,
|
||||||
&iobase);
|
&iobase);
|
||||||
if (err) {
|
if (err) {
|
||||||
dev_err(dev, "Getting bridge resources failed\n");
|
dev_err(dev, "Getting bridge resources failed\n");
|
||||||
|
@ -244,7 +244,8 @@ EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
|
|||||||
|
|
||||||
#if defined(CONFIG_OF_ADDRESS)
|
#if defined(CONFIG_OF_ADDRESS)
|
||||||
/**
|
/**
|
||||||
* of_pci_get_host_bridge_resources - Parse PCI host bridge resources from DT
|
* devm_of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI
|
||||||
|
* host bridge resources from DT
|
||||||
* @dev: host bridge device
|
* @dev: host bridge device
|
||||||
* @busno: bus number associated with the bridge root bus
|
* @busno: bus number associated with the bridge root bus
|
||||||
* @bus_max: maximum number of buses for this bridge
|
* @bus_max: maximum number of buses for this bridge
|
||||||
@ -253,8 +254,6 @@ EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
|
|||||||
* address for the start of the I/O range. Can be NULL if the caller doesn't
|
* address for the start of the I/O range. Can be NULL if the caller doesn't
|
||||||
* expect I/O ranges to be present in the device tree.
|
* expect I/O ranges to be present in the device tree.
|
||||||
*
|
*
|
||||||
* It is the caller's job to free the @resources list.
|
|
||||||
*
|
|
||||||
* This function will parse the "ranges" property of a PCI host bridge device
|
* This function will parse the "ranges" property of a PCI host bridge device
|
||||||
* node and setup the resource mapping based on its content. It is expected
|
* node and setup the resource mapping based on its content. It is expected
|
||||||
* that the property conforms with the Power ePAPR document.
|
* that the property conforms with the Power ePAPR document.
|
||||||
@ -262,12 +261,11 @@ EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
|
|||||||
* It returns zero if the range parsing has been successful or a standard error
|
* It returns zero if the range parsing has been successful or a standard error
|
||||||
* value if it failed.
|
* value if it failed.
|
||||||
*/
|
*/
|
||||||
int of_pci_get_host_bridge_resources(struct device *dev,
|
int devm_of_pci_get_host_bridge_resources(struct device *dev,
|
||||||
unsigned char busno, unsigned char bus_max,
|
unsigned char busno, unsigned char bus_max,
|
||||||
struct list_head *resources, resource_size_t *io_base)
|
struct list_head *resources, resource_size_t *io_base)
|
||||||
{
|
{
|
||||||
struct device_node *dev_node = dev->of_node;
|
struct device_node *dev_node = dev->of_node;
|
||||||
struct resource_entry *window;
|
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
struct resource *bus_range;
|
struct resource *bus_range;
|
||||||
struct of_pci_range range;
|
struct of_pci_range range;
|
||||||
@ -278,7 +276,7 @@ int of_pci_get_host_bridge_resources(struct device *dev,
|
|||||||
if (io_base)
|
if (io_base)
|
||||||
*io_base = (resource_size_t)OF_BAD_ADDR;
|
*io_base = (resource_size_t)OF_BAD_ADDR;
|
||||||
|
|
||||||
bus_range = kzalloc(sizeof(*bus_range), GFP_KERNEL);
|
bus_range = devm_kzalloc(dev, sizeof(*bus_range), GFP_KERNEL);
|
||||||
if (!bus_range)
|
if (!bus_range)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -300,7 +298,7 @@ int of_pci_get_host_bridge_resources(struct device *dev,
|
|||||||
/* Check for ranges property */
|
/* Check for ranges property */
|
||||||
err = of_pci_range_parser_init(&parser, dev_node);
|
err = of_pci_range_parser_init(&parser, dev_node);
|
||||||
if (err)
|
if (err)
|
||||||
goto parse_failed;
|
goto failed;
|
||||||
|
|
||||||
dev_dbg(dev, "Parsing ranges property...\n");
|
dev_dbg(dev, "Parsing ranges property...\n");
|
||||||
for_each_of_pci_range(&parser, &range) {
|
for_each_of_pci_range(&parser, &range) {
|
||||||
@ -322,15 +320,15 @@ int of_pci_get_host_bridge_resources(struct device *dev,
|
|||||||
if (range.cpu_addr == OF_BAD_ADDR || range.size == 0)
|
if (range.cpu_addr == OF_BAD_ADDR || range.size == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
res = kzalloc(sizeof(struct resource), GFP_KERNEL);
|
res = devm_kzalloc(dev, sizeof(struct resource), GFP_KERNEL);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto parse_failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = of_pci_range_to_resource(&range, dev_node, res);
|
err = of_pci_range_to_resource(&range, dev_node, res);
|
||||||
if (err) {
|
if (err) {
|
||||||
kfree(res);
|
devm_kfree(dev, res);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +337,7 @@ int of_pci_get_host_bridge_resources(struct device *dev,
|
|||||||
dev_err(dev, "I/O range found for %pOF. Please provide an io_base pointer to save CPU base address\n",
|
dev_err(dev, "I/O range found for %pOF. Please provide an io_base pointer to save CPU base address\n",
|
||||||
dev_node);
|
dev_node);
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
goto conversion_failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
if (*io_base != (resource_size_t)OF_BAD_ADDR)
|
if (*io_base != (resource_size_t)OF_BAD_ADDR)
|
||||||
dev_warn(dev, "More than one I/O resource converted for %pOF. CPU base address for old range lost!\n",
|
dev_warn(dev, "More than one I/O resource converted for %pOF. CPU base address for old range lost!\n",
|
||||||
@ -352,15 +350,11 @@ int of_pci_get_host_bridge_resources(struct device *dev,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
conversion_failed:
|
failed:
|
||||||
kfree(res);
|
|
||||||
parse_failed:
|
|
||||||
resource_list_for_each_entry(window, resources)
|
|
||||||
kfree(window->res);
|
|
||||||
pci_free_resource_list(resources);
|
pci_free_resource_list(resources);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);
|
EXPORT_SYMBOL_GPL(devm_of_pci_get_host_bridge_resources);
|
||||||
#endif /* CONFIG_OF_ADDRESS */
|
#endif /* CONFIG_OF_ADDRESS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -604,7 +598,7 @@ int pci_parse_request_of_pci_ranges(struct device *dev,
|
|||||||
struct resource_entry *win, *tmp;
|
struct resource_entry *win, *tmp;
|
||||||
|
|
||||||
INIT_LIST_HEAD(resources);
|
INIT_LIST_HEAD(resources);
|
||||||
err = of_pci_get_host_bridge_resources(dev, 0, 0xff, resources,
|
err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, resources,
|
||||||
&iobase);
|
&iobase);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
@ -71,11 +71,11 @@ of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_OF_ADDRESS)
|
#if defined(CONFIG_OF_ADDRESS)
|
||||||
int of_pci_get_host_bridge_resources(struct device *dev,
|
int devm_of_pci_get_host_bridge_resources(struct device *dev,
|
||||||
unsigned char busno, unsigned char bus_max,
|
unsigned char busno, unsigned char bus_max,
|
||||||
struct list_head *resources, resource_size_t *io_base);
|
struct list_head *resources, resource_size_t *io_base);
|
||||||
#else
|
#else
|
||||||
static inline int of_pci_get_host_bridge_resources(struct device *dev,
|
static inline int devm_of_pci_get_host_bridge_resources(struct device *dev,
|
||||||
unsigned char busno, unsigned char bus_max,
|
unsigned char busno, unsigned char bus_max,
|
||||||
struct list_head *resources, resource_size_t *io_base)
|
struct list_head *resources, resource_size_t *io_base)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user