Skip to contentSkip to conversation

psci: Fix refcount leak in psci_dt_init

PATCH New Miaoqian Lin 1 participant 1 message Jun 1, 2022 Power state coordination interface (psci)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 psci: Fix refcount leak in psci_dt_init

of_find_matching_node_and_match() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. When of_device_is_available() fails, call of_node_put() to release the refcount. And of_node_put() will checks NULL pointer.

Fixes d09a0011ec0d ("drivers: psci: Allow PSCI node to be disabled")
---
 drivers/firmware/psci/psci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/firmware/psci/psci.c +3 -1
index cfb448eabdaa..ec888aba57ff 100644
@@ -619,8 +619,10 @@ int __init psci_dt_init(void)
 
 	np = of_find_matching_node_and_match(NULL, psci_of_match, &matched_np);
 
-	if (!np || !of_device_is_available(np))
+	if (!np || !of_device_is_available(np)) {
+		of_node_put(np);
 		return -ENODEV;
+	}
 
 	init_fn = (psci_initcall_t)matched_np->data;
 	ret = init_fn(np);
Signature · 1 line
2.25.1