Skip to contentSkip to conversation

net/mlx5: Fix HCA caps leak on notifier init failure

PATCH Applied Prathamesh Deshpande 4 participants 4 messages Apr 15 – Apr 20

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

PATCH 1/1 net/mlx5: Fix HCA caps leak on notifier init failure

mlx5_mdev_init() allocates HCA caps via mlx5_hca_caps_alloc() before calling mlx5_notifiers_init(). If notifier initialization fails, the error path jumps to err_hca_caps and skips mlx5_hca_caps_free(), leaking allocated caps.

Add a dedicated unwind label for notifier-init failure that frees HCA caps before continuing the existing cleanup sequence.

Fixes b6b03097f982 ("net/mlx5: Initialize events outside devlink lock")
---
 drivers/net/ethernet/mellanox/mlx5/core/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/main.c +3 -1
index 3f73d9b1115d..fab80c79ff07 100644
@@ -1907,7 +1907,7 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
 
 	err = mlx5_notifiers_init(dev);
 	if (err)
-		goto err_hca_caps;
+		goto err_notifiers_init;
 
 	/* The conjunction of sw_vhca_id with sw_owner_id will be a global
 	 * unique id per function which uses mlx5_core.
@@ -1923,6 +1923,8 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
 
 	return 0;
 
+err_notifiers_init:
+	mlx5_hca_caps_free(dev);
 err_hca_caps:
 	mlx5_adev_cleanup(dev);
 err_adev_init:
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Prathamesh Deshpande

mlx5_mdev_init() allocates HCA caps via mlx5_hca_caps_alloc() before calling mlx5_notifiers_init(). If notifier initialization fails, the error path jumps to err_hca_caps and skips mlx5_hca_caps_free(), leaking
allocated caps.

Add a dedicated unwind label for notifier-init failure that frees HCA caps before continuing the existing cleanup sequence.

Fixes b6b03097f982 ("net/mlx5: Initialize events outside devlink

lock")

Thank you for the fix, LGTM!

Quoted 1 line
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Prathamesh Deshpande
Quoted 28 lines · Prathamesh Deshpande

mlx5_mdev_init() allocates HCA caps via mlx5_hca_caps_alloc() before calling mlx5_notifiers_init(). If notifier initialization fails, the error path jumps to err_hca_caps and skips mlx5_hca_caps_free(), leaking allocated caps.

Add a dedicated unwind label for notifier-init failure that frees HCA caps before continuing the existing cleanup sequence.

Fixes b6b03097f982 ("net/mlx5: Initialize events outside devlink lock")
---
  drivers/net/ethernet/mellanox/mlx5/core/main.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/main.c +1 -1
index 3f73d9b1115d..fab80c79ff07 100644
@@ -1907,7 +1907,7 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
 
  	err = mlx5_notifiers_init(dev);
  	if (err)
-		goto err_hca_caps;
+		goto err_notifiers_init;
 
  	/* The conjunction of sw_vhca_id with sw_owner_id will be a global
  	 * unique id per function which uses mlx5_core.

drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx) · line 1930

Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +2 -0
@@ -1923,6 +1923,8 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
 
  	return 0;
 
+err_notifiers_init:
+	mlx5_hca_caps_free(dev);
  err_hca_caps:
  	mlx5_adev_cleanup(dev);
  err_adev_init:

Thanks.

#3 lore raw
In reply to Prathamesh Deshpande
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 9 lines · On Wed, 15 Apr 2026 01:49:37 +0100 you wrote:

mlx5_mdev_init() allocates HCA caps via mlx5_hca_caps_alloc() before calling mlx5_notifiers_init(). If notifier initialization fails, the error path jumps to err_hca_caps and skips mlx5_hca_caps_free(), leaking allocated caps.

Add a dedicated unwind label for notifier-init failure that frees HCA caps before continuing the existing cleanup sequence.

[...]

Here is the summary with links:
- [net,v1] net/mlx5: Fix HCA caps leak on notifier init failure

    https://git.kernel.org/netdev/net/c/d03fc81a5795

You are awesome, thank you!

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