Skip to content

Commit f0b5073

Browse files
ISCAS-VulabPaolo Abeni
authored andcommitted
net/mlx5_core: Add error handling inmlx5_query_nic_vport_qkey_viol_cntr()
The function mlx5_query_nic_vport_qkey_viol_cntr() calls the function mlx5_query_nic_vport_context() but does not check its return value. This could lead to undefined behavior if the query fails. A proper implementation can be found in mlx5_nic_vport_query_local_lb(). Add error handling for mlx5_query_nic_vport_context(). If it fails, free the out buffer via kvfree() and return error code. Fixes: 9efa752 ("net/mlx5_core: Introduce access functions to query vport RoCE fields") Cc: [email protected] # v4.5 Signed-off-by: Wentao Liang <[email protected]> Reviewed-by: Tariq Toukan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 57ee958 commit f0b5073

File tree

1 file changed

+6
-3
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,19 +519,22 @@ int mlx5_query_nic_vport_qkey_viol_cntr(struct mlx5_core_dev *mdev,
519519
{
520520
u32 *out;
521521
int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
522+
int err;
522523

523524
out = kvzalloc(outlen, GFP_KERNEL);
524525
if (!out)
525526
return -ENOMEM;
526527

527-
mlx5_query_nic_vport_context(mdev, 0, out);
528+
err = mlx5_query_nic_vport_context(mdev, 0, out);
529+
if (err)
530+
goto out;
528531

529532
*qkey_viol_cntr = MLX5_GET(query_nic_vport_context_out, out,
530533
nic_vport_context.qkey_violation_counter);
531-
534+
out:
532535
kvfree(out);
533536

534-
return 0;
537+
return err;
535538
}
536539
EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_qkey_viol_cntr);
537540

0 commit comments

Comments
 (0)