Skip to content

Commit f31231b

Browse files
Colin Ian Kingmstsirkin
authored andcommitted
vdpa/mlx5: fix memory allocation failure checks
The memory allocation failure checking for in and out is currently checking if the pointers are valid rather than the contents of what they point to. Hence the null check on failed memory allocations is incorrect. Fix this by adding the missing indirection in the check. Also for the default case, just set the *in and *out to null as these don't have any thing allocated to kfree. Finally remove the redundant *in and *out check as these have been already done on each allocation in the case statement. Addresses-Coverity: ("Null pointer dereference") Fixes: 1a86b37 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices") Signed-off-by: Colin Ian King <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]> Acked-by: Eli Cohen <[email protected]>
1 parent 05acc4b commit f31231b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
867867
*outlen = MLX5_ST_SZ_BYTES(qp_2rst_out);
868868
*in = kzalloc(*inlen, GFP_KERNEL);
869869
*out = kzalloc(*outlen, GFP_KERNEL);
870-
if (!in || !out)
870+
if (!*in || !*out)
871871
goto outerr;
872872

873873
MLX5_SET(qp_2rst_in, *in, opcode, cmd);
@@ -879,7 +879,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
879879
*outlen = MLX5_ST_SZ_BYTES(rst2init_qp_out);
880880
*in = kzalloc(*inlen, GFP_KERNEL);
881881
*out = kzalloc(MLX5_ST_SZ_BYTES(rst2init_qp_out), GFP_KERNEL);
882-
if (!in || !out)
882+
if (!*in || !*out)
883883
goto outerr;
884884

885885
MLX5_SET(rst2init_qp_in, *in, opcode, cmd);
@@ -896,7 +896,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
896896
*outlen = MLX5_ST_SZ_BYTES(init2rtr_qp_out);
897897
*in = kzalloc(*inlen, GFP_KERNEL);
898898
*out = kzalloc(MLX5_ST_SZ_BYTES(init2rtr_qp_out), GFP_KERNEL);
899-
if (!in || !out)
899+
if (!*in || !*out)
900900
goto outerr;
901901

902902
MLX5_SET(init2rtr_qp_in, *in, opcode, cmd);
@@ -914,7 +914,7 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
914914
*outlen = MLX5_ST_SZ_BYTES(rtr2rts_qp_out);
915915
*in = kzalloc(*inlen, GFP_KERNEL);
916916
*out = kzalloc(MLX5_ST_SZ_BYTES(rtr2rts_qp_out), GFP_KERNEL);
917-
if (!in || !out)
917+
if (!*in || !*out)
918918
goto outerr;
919919

920920
MLX5_SET(rtr2rts_qp_in, *in, opcode, cmd);
@@ -927,16 +927,15 @@ static void alloc_inout(struct mlx5_vdpa_net *ndev, int cmd, void **in, int *inl
927927
MLX5_SET(qpc, qpc, rnr_retry, 7);
928928
break;
929929
default:
930-
goto outerr;
930+
goto outerr_nullify;
931931
}
932-
if (!*in || !*out)
933-
goto outerr;
934932

935933
return;
936934

937935
outerr:
938936
kfree(*in);
939937
kfree(*out);
938+
outerr_nullify:
940939
*in = NULL;
941940
*out = NULL;
942941
}

0 commit comments

Comments
 (0)