]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
can: at91_can: Fix memory leak in at91_can_probe()
authorZilin Guan <zilin@seu.edu.cn>
Thu, 22 Jan 2026 11:41:28 +0000 (11:41 +0000)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Thu, 22 Jan 2026 15:56:26 +0000 (16:56 +0100)
In at91_can_probe(), the dev structure is allocated via alloc_candev().
However, if the subsequent call to devm_phy_optional_get() fails, the
code jumps directly to exit_iounmap, missing the call to free_candev().
This results in a memory leak of the allocated net_device structure.

Fix this by jumping to the exit_free label instead, which ensures that
free_candev() is called to properly release the memory.

Compile tested only. Issue found using a prototype static analysis tool
and code review.

Fixes: 3ecc09856afb ("can: at91_can: add CAN transceiver support")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Link: https://patch.msgid.link/20260122114128.643752-1-zilin@seu.edu.cn
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/at91_can.c

index c2a3a4eef5b281f6723e3fa7a40bba1a1d623a54..58da323f14d7c14652860f27d1cb25fa6a234901 100644 (file)
@@ -1099,7 +1099,7 @@ static int at91_can_probe(struct platform_device *pdev)
        if (IS_ERR(transceiver)) {
                err = PTR_ERR(transceiver);
                dev_err_probe(&pdev->dev, err, "failed to get phy\n");
-               goto exit_iounmap;
+               goto exit_free;
        }
 
        dev->netdev_ops = &at91_netdev_ops;