2022-06-29 08:55:30

by Jianglei Nie

[permalink] [raw]
Subject: [PATCH net v3] net: sfp: fix memory leak in sfp_probe()

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 <[email protected]>
---
drivers/net/phy/sfp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 9a5d5a10560f..e7b0e12cc75b 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -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;

--
2.25.1


2022-06-29 10:04:15

by Russell King (Oracle)

[permalink] [raw]
Subject: Re: [PATCH net v3] net: sfp: fix memory leak in sfp_probe()

On Wed, Jun 29, 2022 at 03:55:50PM +0800, Jianglei Nie wrote:
> 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 <[email protected]>

Thanks!

Reviewed-by: Russell King (Oracle) <[email protected]>

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

2022-06-30 10:37:30

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net v3] net: sfp: fix memory leak in sfp_probe()

Hello:

This patch was applied to netdev/net.git (master)
by Paolo Abeni <[email protected]>:

On Wed, 29 Jun 2022 15:55:50 +0800 you wrote:
> 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 <[email protected]>
>
> [...]

Here is the summary with links:
- [net,v3] net: sfp: fix memory leak in sfp_probe()
https://git.kernel.org/netdev/net/c/0a18d802d65c

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html