Skip to contentSkip to conversation

bus: arm-cci: Fix OF node refcount leak in cci_probe()

PATCH In review Yuho Choi 1 participant 2 messages May 1 – Jun 3

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 bus: arm-cci: Fix OF node refcount leak in cci_probe()

of_find_matching_node() returns a device node with its reference count incremented. cci_probe() returns without dropping that reference when the matched node is unavailable, when controller mapping fails, and after cci_probe_ports() returns.

Route all exits after the lookup through a common cleanup label and drop the node with of_node_put(). This is also safe for the no-match case because of_node_put(NULL) is allowed.

Fixes ed69bdd8fd9b ("drivers: bus: add ARM CCI support")
---
 drivers/bus/arm-cci.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/bus/arm-cci.c +11 -4
index 7f2baf057128..f5993380d511 100644
@@ -538,8 +538,10 @@ static int cci_probe(void)
 	struct resource res;
 
 	np = of_find_matching_node(NULL, arm_cci_matches);
-	if (!of_device_is_available(np))
-		return -ENODEV;
+	if (!of_device_is_available(np)) {
+		ret = -ENODEV;
+		goto out_put_node;
+	}
 
 	ret = of_address_to_resource(np, 0, &res);
 	if (!ret) {
@@ -548,10 +550,15 @@ static int cci_probe(void)
 	}
 	if (ret || !cci_ctrl_base) {
 		WARN(1, "unable to ioremap CCI ctrl\n");
-		return -ENXIO;
+		ret = -ENXIO;
+		goto out_put_node;
 	}
 
-	return cci_probe_ports(np);
+	ret = cci_probe_ports(np);
+
+out_put_node:
+	of_node_put(np);
+	return ret;
 }
 
 static int cci_init_status = -EAGAIN;
Signature · 1 line
2.43.0
author
#1 lore raw

Hi,

Just a gentle reminder regarding this patch.

I would appreciate any feedback when you have a chance to review it.

Thanks for your time.

Best regards,
Yuho Choi