* [PATCH net-next v2] net: sfp: fix hwmon_name memory leak on hwmon registration failure
@ 2026-08-09 6:45 Krishan Singh
2026-08-09 15:01 ` Andrew Lunn
2026-08-11 0:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Krishan Singh @ 2026-08-09 6:45 UTC (permalink / raw)
To: linux
Cc: andrew, hkallweit1, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, Krishan Singh
hwmon_sanitize_name() allocates sfp->hwmon_name before
hwmon_device_register_with_info() is called. If the registration
fails, sfp->hwmon_dev is left pointing to an error while
sfp->hwmon_name remains allocated.
Later, when the SFP module is removed, sfp_hwmon_remove() only frees
hwmon_name when hwmon_dev is valid. As a result, hwmon_name is leaked
if hwmon_device_register_with_info() fails.
Free hwmon_name independently of hwmon_dev. Continue to unregister the
hwmon device only when hwmon_dev was successfully registered.
Fixes: 3f118c449c8e ("net: sfp: use hwmon_sanitize_name()")
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Krishan Singh <krishanmohan298@gmail.com>
---
v2:
- Move hwmon_name cleanup to sfp_hwmon_remove().
- Free hwmon_name independently of hwmon_dev.
---
drivers/net/phy/sfp.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index f52020673..bfa2b821f 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -1916,7 +1916,11 @@ static void sfp_hwmon_remove(struct sfp *sfp)
if (!IS_ERR_OR_NULL(sfp->hwmon_dev)) {
hwmon_device_unregister(sfp->hwmon_dev);
sfp->hwmon_dev = NULL;
+ }
+
+ if (!IS_ERR_OR_NULL(sfp->hwmon_name)) {
kfree(sfp->hwmon_name);
+ sfp->hwmon_name = NULL;
}
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next v2] net: sfp: fix hwmon_name memory leak on hwmon registration failure
2026-08-09 6:45 [PATCH net-next v2] net: sfp: fix hwmon_name memory leak on hwmon registration failure Krishan Singh
@ 2026-08-09 15:01 ` Andrew Lunn
2026-08-11 0:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2026-08-09 15:01 UTC (permalink / raw)
To: Krishan Singh
Cc: linux, hkallweit1, davem, edumazet, kuba, pabeni, netdev,
linux-kernel
On Sun, Aug 09, 2026 at 12:15:04PM +0530, Krishan Singh wrote:
> hwmon_sanitize_name() allocates sfp->hwmon_name before
> hwmon_device_register_with_info() is called. If the registration
> fails, sfp->hwmon_dev is left pointing to an error while
> sfp->hwmon_name remains allocated.
>
> Later, when the SFP module is removed, sfp_hwmon_remove() only frees
> hwmon_name when hwmon_dev is valid. As a result, hwmon_name is leaked
> if hwmon_device_register_with_info() fails.
>
> Free hwmon_name independently of hwmon_dev. Continue to unregister the
> hwmon device only when hwmon_dev was successfully registered.
>
> Fixes: 3f118c449c8e ("net: sfp: use hwmon_sanitize_name()")
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Krishan Singh <krishanmohan298@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net-next v2] net: sfp: fix hwmon_name memory leak on hwmon registration failure
2026-08-09 6:45 [PATCH net-next v2] net: sfp: fix hwmon_name memory leak on hwmon registration failure Krishan Singh
2026-08-09 15:01 ` Andrew Lunn
@ 2026-08-11 0:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-08-11 0:20 UTC (permalink / raw)
To: Krishan Singh
Cc: linux, andrew, hkallweit1, davem, edumazet, kuba, pabeni, netdev,
linux-kernel
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sun, 9 Aug 2026 12:15:04 +0530 you wrote:
> hwmon_sanitize_name() allocates sfp->hwmon_name before
> hwmon_device_register_with_info() is called. If the registration
> fails, sfp->hwmon_dev is left pointing to an error while
> sfp->hwmon_name remains allocated.
>
> Later, when the SFP module is removed, sfp_hwmon_remove() only frees
> hwmon_name when hwmon_dev is valid. As a result, hwmon_name is leaked
> if hwmon_device_register_with_info() fails.
>
> [...]
Here is the summary with links:
- [net-next,v2] net: sfp: fix hwmon_name memory leak on hwmon registration failure
https://git.kernel.org/netdev/net-next/c/20232e99e8bf
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-11 0:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-09 6:45 [PATCH net-next v2] net: sfp: fix hwmon_name memory leak on hwmon registration failure Krishan Singh
2026-08-09 15:01 ` Andrew Lunn
2026-08-11 0:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox