can: sun4i_can: Fix clk leak in sun4ican_probe()
Subsystems (3)
PATCH 1/1 can: sun4i_can: Fix clk leak in sun4ican_probe()
In sun4ican_probe(), the clock is obtained with of_clk_get(), which returns a reference that must be released with clk_put(). If platform_get_irq(), devm_platform_ioremap_resource(), alloc_candev() or register_candev() fails, the reference is never released, leaking the clock.
Fix this by adding an exit_put_clk label that releases the clock and jumping to it from all error paths after the of_clk_get() call.
Fixes 0738eff14d81 ("can: Allwinner A10/A20 CAN Controller support - Kernel module")
Signed-off-by Wentao Liang <[email protected]>
--- drivers/net/can/sun4i_can.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/can/sun4i_can.c +5 -3
@@ -854,13 +854,13 @@ static int sun4ican_probe(struct platform_device *pdev) irq =platform_get_irq (pdev,0 );if (irq <0 ) { err = -ENODEV ; - goto exit; + goto exit_put_clk; } addr =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (addr)) { err =PTR_ERR (addr); - goto exit; + goto exit_put_clk; } dev =alloc_candev (sizeof (struct sun4ican_priv ),1 );
@@ -868,7 +868,7 @@ static int sun4ican_probe(struct platform_device *pdev)dev_err (&pdev->dev,"could not allocate memory for CAN device\n" ); err = -ENOMEM ; - goto exit; + goto exit_put_clk; } dev->netdev_ops = &sun4ican_netdev_ops;
@@ -908,6 +908,8 @@ static int sun4ican_probe(struct platform_device *pdev) exit_free:free_candev (dev); +exit_put_clk: +clk_put (clk); exit:return err; }
Signature · 1 line
2.34.1