]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: sfp: fix memory leak in sfp_probe()
authorJianglei Nie <niejianglei2021@163.com>
Wed, 29 Jun 2022 07:55:50 +0000 (15:55 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 30 Jun 2022 09:38:16 +0000 (11:38 +0200)
sfp_probe() allocates a memory chunk from sfp with sfp_alloc(). When
devm_add_action() fails, sfp is not freed, which leads to a memory leak.

We should use devm_add_action_or_reset() instead of devm_add_action().

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://lore.kernel.org/r/20220629075550.2152003-1-niejianglei2021@163.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/phy/sfp.c

index 9a5d5a10560fb135d5b7a547795dfcdce6e94377..e7b0e12cc75bf3825ebf8d2044f6d6f92d95bf13 100644 (file)
@@ -2516,7 +2516,7 @@ static int sfp_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, sfp);
 
-       err = devm_add_action(sfp->dev, sfp_cleanup, sfp);
+       err = devm_add_action_or_reset(sfp->dev, sfp_cleanup, sfp);
        if (err < 0)
                return err;