net/mlx5: Fix HCA caps leak on notifier init failure
Subsystems (4)
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.
--- 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
@@ -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
Quoted 11 lines · Prathamesh Deshpande
mlx5_mdev_init()allocates HCA caps viamlx5_hca_caps_alloc()before callingmlx5_notifiers_init(). If notifier initialization fails, the error path jumps toerr_hca_capsand skipsmlx5_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 devlinklock")
Thank you for the fix, LGTM!
Quoted 1 line
Signed-off-by Prathamesh Deshpande <[email protected]>
Quoted 28 lines · Prathamesh Deshpande
mlx5_mdev_init()allocates HCA caps viamlx5_hca_caps_alloc()before callingmlx5_notifiers_init(). If notifier initialization fails, the error path jumps toerr_hca_capsand skipsmlx5_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")Signed-off-by Prathamesh Deshpande <[email protected]>--- 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@@ -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.
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 viamlx5_hca_caps_alloc()before callingmlx5_notifiers_init(). If notifier initialization fails, the error path jumps toerr_hca_capsand skipsmlx5_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