mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mlxsw: core_hwmon: unregister the hwmon device on event ops failure
@ 2026-11-03 10:28 Wentao Liang
  2026-11-03 10:33 ` netdev-bot+sinfo
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-11-03 10:28 UTC (permalink / raw)
  To: Ido Schimmel, Petr Machata, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Wentao Liang, stable

If mlxsw_linecards_event_ops_register() fails, the error path calls
hwmon_device_unregister() with line_cards[0].hwmon_dev, but that field
is assigned only after the registration succeeds and is therefore
still NULL. The hwmon device returned by
hwmon_device_register_with_groups() is never unregistered, and the
error path dereferences a NULL device.

Unregister the hwmon_dev local variable instead.

Fixes: 99a03b3193f6 ("mlxsw: core_hwmon: Add interfaces for line card initialization and de-initialization")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c b/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c
index a5e7aee730d6..16644f367df6 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c
@@ -920,7 +920,7 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
 	return 0;
 
 err_linecards_event_ops_register:
-	hwmon_device_unregister(mlxsw_hwmon->line_cards[0].hwmon_dev);
+	hwmon_device_unregister(hwmon_dev);
 err_hwmon_register:
 err_temp_gearbox_init:
 err_temp_module_init:
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-03 10:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 10:28 [PATCH] mlxsw: core_hwmon: unregister the hwmon device on event ops failure Wentao Liang
2026-11-03 10:33 ` netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®