Netdev List
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Krishan Singh <krishanmohan298@gmail.com>
Cc: linux@armlinux.org.uk, hkallweit1@gmail.com, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: sfp: Fix memory leak of hwmon_name on hwmon registration failure
Date: Wed, 5 Aug 2026 13:58:27 +0200	[thread overview]
Message-ID: <4effcfad-50db-43e4-9e6a-7227525cc53f@lunn.ch> (raw)
In-Reply-To: <20260805043643.194976-1-krishanmohan298@gmail.com>

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 <andrew@lunn.ch>
>     Signed-off-by: Krishan Singh <krishanmohan298@gmail.com>
> ---

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

  reply	other threads:[~2026-08-05 11:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  4:36 [PATCH] net: sfp: Fix memory leak of hwmon_name on hwmon registration failure Krishan Singh
2026-08-05 11:58 ` Andrew Lunn [this message]
2026-08-07  7:22   ` krishan mohan
2026-08-07 14:01     ` Andrew Lunn
  -- strict thread matches above, loose matches on Subject: below --
2026-08-05  4:24 Krishan Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4effcfad-50db-43e4-9e6a-7227525cc53f@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=krishanmohan298@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox