can: ti_hecc: Fix memleak in ti_hecc_probe
authorZhang Qilong <zhangqilong3@huawei.com>
Sat, 14 Nov 2020 11:17:08 +0000 (19:17 +0800)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Sun, 15 Nov 2020 17:24:35 +0000 (18:24 +0100)
In the error handling, we should goto the probe_exit_candev
to free ndev to prevent memory leak.

Fixes: dabf54dd1c63 ("can: ti_hecc: Convert TI HECC driver to DT only driver")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Link: https://lore.kernel.org/r/20201114111708.3465543-1-zhangqilong3@huawei.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/ti_hecc.c

index 9913f5458279b66a4d02774838e23c0d2657e3fd..2c22f40e12bdf1b1be927c29b6f11e5587098f98 100644 (file)
@@ -881,7 +881,8 @@ static int ti_hecc_probe(struct platform_device *pdev)
        priv->base = devm_platform_ioremap_resource_byname(pdev, "hecc");
        if (IS_ERR(priv->base)) {
                dev_err(&pdev->dev, "hecc ioremap failed\n");
-               return PTR_ERR(priv->base);
+               err = PTR_ERR(priv->base);
+               goto probe_exit_candev;
        }
 
        /* handle hecc-ram memory */
@@ -889,20 +890,22 @@ static int ti_hecc_probe(struct platform_device *pdev)
                                                               "hecc-ram");
        if (IS_ERR(priv->hecc_ram)) {
                dev_err(&pdev->dev, "hecc-ram ioremap failed\n");
-               return PTR_ERR(priv->hecc_ram);
+               err = PTR_ERR(priv->hecc_ram);
+               goto probe_exit_candev;
        }
 
        /* handle mbx memory */
        priv->mbx = devm_platform_ioremap_resource_byname(pdev, "mbx");
        if (IS_ERR(priv->mbx)) {
                dev_err(&pdev->dev, "mbx ioremap failed\n");
-               return PTR_ERR(priv->mbx);
+               err = PTR_ERR(priv->mbx);
+               goto probe_exit_candev;
        }
 
        irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
        if (!irq) {
                dev_err(&pdev->dev, "No irq resource\n");
-               goto probe_exit;
+               goto probe_exit_candev;
        }
 
        priv->ndev = ndev;
@@ -966,7 +969,7 @@ probe_exit_release_clk:
        clk_put(priv->clk);
 probe_exit_candev:
        free_candev(ndev);
-probe_exit:
+
        return err;
 }