Skip to contentSkip to conversation

drivers: of: fix resources freeing in of_pci_get_host_bridge_resources()

PATCH New Lorenzo Pieralisi 2 participants 2 messages Jan 27, 2015 – Jan 28, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: of: fix resources freeing in of_pci_get_host_bridge_resources()

In the function of_pci_get_host_bridge_resources() if the parsing of ranges fails, previously allocated resources inclusive of bus_range are not freed and are not expected to be freed by the function caller on error return.

This patch fixes the issues by adding code that properly frees resources and bus_range before exiting the function with an error return value.

---
 drivers/of/of_pci.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/of/of_pci.c +4 -0
index 88471d3..60dc36c 100644
@@ -140,6 +140,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base)
 {
+	struct pci_host_bridge_window *window;
 	struct resource *res;
 	struct resource *bus_range;
 	struct of_pci_range range;
@@ -225,7 +226,10 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
 conversion_failed:
 	kfree(res);
 parse_failed:
+	list_for_each_entry(window, resources, list)
+		kfree(window->res);
 	pci_free_resource_list(resources);
+	kfree(bus_range);
 	return err;
 }
 EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);
Signature · 1 line
2.2.1
maintainer Applied
#1 lore raw

PATCH 1/1 drivers: of: fix resources freeing in of_pci_get_host_bridge_resources()

Quoted 5 lines · Lorenzo Pieralisi

In the function of_pci_get_host_bridge_resources() if the parsing of ranges fails, previously allocated resources inclusive of bus_range are not freed and are not expected to be freed by the function caller on error return.

Quoted 8 lines

This patch fixes the issues by adding code that properly frees resources and bus_range before exiting the function with an error return value.

Applied to pci/host-generic for v3.20, thanks!

Quoted 30 lines
---
 drivers/of/of_pci.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/of/of_pci.c +4 -0
index 88471d3..60dc36c 100644
@@ -140,6 +140,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
 			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources, resource_size_t *io_base)
 {
+	struct pci_host_bridge_window *window;
 	struct resource *res;
 	struct resource *bus_range;
 	struct of_pci_range range;
@@ -225,7 +226,10 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
 conversion_failed:
 	kfree(res);
 parse_failed:
+	list_for_each_entry(window, resources, list)
+		kfree(window->res);
 	pci_free_resource_list(resources);
+	kfree(bus_range);
 	return err;
 }
 EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources);
Signature · 1 line
2.2.1