Netdev List
 help / color / mirror / Atom feed
From: Janis Edvarts Lacis <janislacis06@gmail.com>
To: andrew@lunn.ch
Cc: davem@davemloft.net, edumazet@google.com, hkallweit1@gmail.com,
	krishanmohan298@gmail.com, kuba@kernel.org,
	linux-kernel@vger.kernel.org, linux@armlinux.org.uk,
	netdev@vger.kernel.org, pabeni@redhat.com
Subject: Re: [PATCH] net: sfp: fix hwmon_name leak on hwmon registration failure
Date: Sun,  2 Aug 2026 00:33:15 +0300	[thread overview]
Message-ID: <20260801213315.536335-1-janislacis06@gmail.com> (raw)
In-Reply-To: <66ac9090-fdb6-404d-aa75-bd3adf8578ea@lunn.ch>

I have looked into the code for sfp_hwmon_remove calls to the 
best of my abilities and Andrew is right that sfp_hwmon_remove 
is called on every sfp device. 

If sfp_hwmon_probe fails in hwmon_device_register_with_info function call,
it leaves sfp->hwmon_dev as an error pointer. When sfp_check_state detects 
that SFP_F_PRESENT has changed, it sends SFP_E_REMOVE which leads to sfp_hwmon_remove  
call. In sfp_hwmon_remove sfp->hwmon_name is not freed because
!IS_ERR_OR_NULL(sfp->hwmon_dev) is false therefore the whole cleanup block is skipped.

So, as Andrew suggested, freeing sfp->hwmon_name if it is not NULL
and it is not an error pointer (hwmon_sanitize_name can return an error 
pointer) instead of freeing only when sfp->hwmon_dev is valid seems
to be the correct approach.

      reply	other threads:[~2026-08-01 21:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-01  6:57 [PATCH] net: sfp: fix hwmon_name leak on hwmon registration failure Krishan Singh
2026-08-01 19:56 ` Andrew Lunn
2026-08-01 21:33   ` Janis Edvarts Lacis [this message]

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=20260801213315.536335-1-janislacis06@gmail.com \
    --to=janislacis06@gmail.com \
    --cc=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