Re: [PATCH] net: sfp: Fix memory leak of hwmon_name on hwmon registration failure

Andrew Lunn <[email protected]>
Newsgroups org.kernel.vger.netdev,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Wed, Aug 05, 2026 at 10:06:43AM +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 as an error pointer while
>     sfp->hwmon_name remains allocated.
> 
>     Later, when the SFP module is removed, sfp_hwmon_remove() is still
>     called. However, it frees sfp->hwmon_name only when
>     !IS_ERR_OR_NULL(sfp->hwmon_dev) is true. Since sfp->hwmon_dev is an
>     error pointer in the failure case, the cleanup block is skipped and
>     hwmon_name is leaked.
> 
>     Fix this by cleaning up hwmon_name independently of hwmon_dev.
>     Continue to unregister the hwmon device only when hwmon_dev is valid,
>     but free hwmon_name whenever it is a valid allocated pointer.
> 
>     Fixes: 3f118c449c8e ("net: sfp: use hwmon_sanitize_name()")
>     Suggested-by: Andrew Lunn <[email protected]>
>     Signed-off-by: Krishan Singh <[email protected]>
> ---

Please read

https://docs.kernel.org/process/submitting-patches.html

There should be a version number in the Subject: line, and under the
--- a version history.

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

For netdev, we want the tree to be indicated in the Subject: line. For
this patch i would suggest net-next.

    Andrew

---
pw-bot: cr
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.