Re: [PATCH] net: sfp: fix hwmon_name leak on hwmon registration failure

From: Andrew Lunn

Date: Sat Aug 01 2026 - 16:01:02 EST


On Sat, Aug 01, 2026 at 12:27:03PM +0530, Krishan Singh wrote:
> When hwmon_device_register_with_info() fails in sfp_hwmon_probe(),
> the string allocated by hwmon_sanitize_name() is not freed, leaking
> memory on repeated hotplug/probe attempts.

Have you actually seen this, or is this theoretical?

I'm not too familiar with this code, but what i find interesting is
that sfp_hwmon_probe() is a void function. It has no way to say the
probe has failed. So how does the caller know it failed, and it should
not call sfp_hwmon_remove()? I suspect sfp_hwmon_remove() is always
called. So sfp_hwmon_remove() should be changed to release the
hwmon_name if it is not NULL.


Andrew

---
pw-bot: cr