Skip to content

Commit 70f238c

Browse files
saviramnvidiarleon
authored andcommitted
net/mlx5: Check device memory pointer before usage
Add a NULL check before accessing device memory to prevent a crash if dev->dm allocation in mlx5_init_once() fails. Fixes: c9b9dcb ("net/mlx5: Move device memory management to mlx5_core") Signed-off-by: Stav Aviram <saviram@nvidia.com> Link: https://patch.msgid.link/c88711327f4d74d5cebc730dc629607e989ca187.1751370035.git.leon@kernel.org Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent 02943ac commit 70f238c

3 files changed

Lines changed: 3 additions & 6 deletions

File tree

  • drivers

drivers/infiniband/hw/mlx5/dm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static struct ib_dm *handle_alloc_dm_memic(struct ib_ucontext *ctx,
282282
int err;
283283
u64 address;
284284

285-
if (!MLX5_CAP_DEV_MEM(dm_db->dev, memic))
285+
if (!dm_db || !MLX5_CAP_DEV_MEM(dm_db->dev, memic))
286286
return ERR_PTR(-EOPNOTSUPP);
287287

288288
dm = kzalloc(sizeof(*dm), GFP_KERNEL);

drivers/net/ethernet/mellanox/mlx5/core/lib/dm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
3030

3131
dm = kzalloc(sizeof(*dm), GFP_KERNEL);
3232
if (!dm)
33-
return ERR_PTR(-ENOMEM);
33+
return NULL;
3434

3535
spin_lock_init(&dm->lock);
3636

@@ -96,7 +96,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
9696
err_steering:
9797
kfree(dm);
9898

99-
return ERR_PTR(-ENOMEM);
99+
return NULL;
100100
}
101101

102102
void mlx5_dm_cleanup(struct mlx5_core_dev *dev)

drivers/net/ethernet/mellanox/mlx5/core/main.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,9 +1102,6 @@ static int mlx5_init_once(struct mlx5_core_dev *dev)
11021102
}
11031103

11041104
dev->dm = mlx5_dm_create(dev);
1105-
if (IS_ERR(dev->dm))
1106-
mlx5_core_warn(dev, "Failed to init device memory %ld\n", PTR_ERR(dev->dm));
1107-
11081105
dev->tracer = mlx5_fw_tracer_create(dev);
11091106
dev->hv_vhca = mlx5_hv_vhca_create(dev);
11101107
dev->rsc_dump = mlx5_rsc_dump_create(dev);

0 commit comments

Comments
 (0)