If alloc_hdlcdev() or register_hdlc_device() fails after
uhdlc_init() succeeds, ucc_hdlc_probe() fails to free the
resources acquired by uhdlc_init(), causing a resource leak.

Fix this by calling uhdlc_memclean() on both error paths.

Found it by self-developed static analysis tool and compile-
test passed.

Fixes: c19b6d246a35 ("drivers/net: support hdlc function for QE-UCC")
Signed-off-by: Wanhui Fu <[email protected]>
---
 drivers/net/wan/fsl_ucc_hdlc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wan/fsl_ucc_hdlc.c b/drivers/net/wan/fsl_ucc_hdlc.c
index 809f21fb93f5..7f2ff519d9c1 100644
--- a/drivers/net/wan/fsl_ucc_hdlc.c
+++ b/drivers/net/wan/fsl_ucc_hdlc.c
@@ -1216,7 +1216,7 @@ static int ucc_hdlc_probe(struct platform_device *pdev)
        if (!dev) {
                ret = -ENOMEM;
                pr_err("ucc_hdlc: unable to allocate memory\n");
-               goto undo_uhdlc_init;
+               goto clean_uhdlc;
        }
 
        uhdlc_priv->ndev = dev;
@@ -1237,6 +1237,8 @@ static int ucc_hdlc_probe(struct platform_device *pdev)
 
 free_dev:
        free_netdev(dev);
+clean_uhdlc:
+       uhdlc_memclean(uhdlc_priv);
 undo_uhdlc_init:
        if (utdm)
                iounmap(utdm->siram);
-- 
2.25.1


Reply via email to