]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net/mlx5: Fix HCA caps leak on notifier init failure
authorPrathamesh Deshpande <prathameshdeshpande7@gmail.com>
Wed, 15 Apr 2026 00:49:37 +0000 (01:49 +0100)
committerJakub Kicinski <kuba@kernel.org>
Mon, 20 Apr 2026 18:42:30 +0000 (11:42 -0700)
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")
Signed-off-by: Prathamesh Deshpande <prathameshdeshpande7@gmail.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260415005022.34764-1-prathameshdeshpande7@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/main.c

index b4501cdc235125a0a028966e217effa3df1ef56b..09c57841e48de06b0912490a1d266b35fd57422c 100644 (file)
@@ -1914,7 +1914,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.
@@ -1930,6 +1930,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: