Re: [PATCH net-next v2] net: sfp: fix hwmon_name memory leak on hwmon registration failure

Andrew Lunn <[email protected]>
Newsgroups gmane.linux.network,gmane.linux.kernel
Message-ID <[email protected]>
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 <[email protected]>
> Signed-off-by: Krishan Singh <[email protected]>

Reviewed-by: Andrew Lunn <[email protected]>

    Andrew
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.