The call to of_find_matching_node_and_match returns a node pointer
with refcount incremented thus it must be explicitly decremented
after the last usage.

672 int __init psci_dt_init(void)
673 {
674         struct device_node *np;
    ...
678         np = of_find_matching_node_and_match(...);
679
680         if (!np || !of_device_is_available(np))
682                 return -ENODEV;  ---> leaked here
    ...
686         return init_fn(np);      ---> released here
687 }

Detected by using coccinelle.

Signed-off-by: Wen Yang <wen.yan...@zte.com.cn>
Cc: Mark Rutland <mark.rutl...@arm.com>
Cc: Lorenzo Pieralisi <lorenzo.pieral...@arm.com>
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/firmware/psci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c
index c80ec1d..e4143f8 100644
--- a/drivers/firmware/psci.c
+++ b/drivers/firmware/psci.c
@@ -677,8 +677,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;
        return init_fn(np);
-- 
2.9.5

Reply via email to