mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 01:11:51 -04:00
net: sfp: fix hwmon_name memory leak on hwmon registration failure
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. Cc: stable+noautosel@kernel.org # untested fix to unlikely driver error path Suggested-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Krishan Singh <krishanmohan298@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Link: https://patch.msgid.link/20260809064504.70579-1-krishanmohan298@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
ab40240945
commit
20232e99e8
@@ -1919,7 +1919,11 @@ static void sfp_hwmon_remove(struct sfp *sfp)
|
||||
if (!IS_ERR_OR_NULL(sfp->hwmon_dev)) {
|
||||
hwmon_device_unregister(sfp->hwmon_dev);
|
||||
sfp->hwmon_dev = NULL;
|
||||
}
|
||||
|
||||
if (!IS_ERR_OR_NULL(sfp->hwmon_name)) {
|
||||
kfree(sfp->hwmon_name);
|
||||
sfp->hwmon_name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user