The immr_node variable is still being used after the of_node_put() call,
which may result in use-after-free.
Fix this issue by calling of_node_put() after the last usage.

Fixes: fd066e850351 ("powerpc/mpc8308: fix USB DR controller initialization")
Signed-off-by: Wen Yang <wen.yan...@zte.com.cn>
Cc: Scott Wood <o...@buserror.net>
Cc: Kumar Gala <ga...@kernel.crashing.org>
Cc: Benjamin Herrenschmidt <b...@kernel.crashing.org>
Cc: Paul Mackerras <pau...@samba.org>
Cc: Michael Ellerman <m...@ellerman.id.au>
Cc: Markus Elfring <markus.elfr...@web.de>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-ker...@vger.kernel.org
---
 arch/powerpc/platforms/83xx/usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/83xx/usb.c 
b/arch/powerpc/platforms/83xx/usb.c
index 3d247d7..19dcef5 100644
--- a/arch/powerpc/platforms/83xx/usb.c
+++ b/arch/powerpc/platforms/83xx/usb.c
@@ -158,11 +158,10 @@ int mpc831x_usb_cfg(void)
 
        iounmap(immap);
 
-       of_node_put(immr_node);
-
        /* Map USB SOC space */
        ret = of_address_to_resource(np, 0, &res);
        if (ret) {
+               of_node_put(immr_node);
                of_node_put(np);
                return ret;
        }
@@ -203,6 +202,7 @@ int mpc831x_usb_cfg(void)
 
 out:
        iounmap(usb_regs);
+       of_node_put(immr_node);
        of_node_put(np);
        return ret;
 }
-- 
2.9.5

Reply via email to