Skip to contentSkip to conversation

mlxsw: core_hwmon: unregister the hwmon device on event ops failure

PATCH Applied Wentao Liang 4 participants 4 messages Nov 3 – Nov 6

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mlxsw: core_hwmon: unregister the hwmon device on event ops failure

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")
Assisted-by DeepSeek-V4.1-Flash and OpenAI Codex
---
 drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c +1 -1
index a5e7aee730d6..16644f367df6 100644
@@ -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:
Signature · 1 line
2.34.1
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Wentao Liang
Quoted 7 lines · Wentao Liang

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.

Quoted 6 lines

Unregister the hwmon_dev local variable instead.

Fixes 99a03b3193f6 ("mlxsw: core_hwmon: Add interfaces for line card initialization and de-initialization")
Assisted-by DeepSeek-V4.1-Flash and OpenAI Codex
#3 lore raw
In reply to Wentao Liang
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 3 Nov 2026 10:28:50 +0000 you wrote:

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.

[...]

Here is the summary with links:
- mlxsw: core_hwmon: unregister the hwmon device on event ops failure

    https://git.kernel.org/netdev/net-next/c/08f643794931

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html