diff mbox

[libmlx5,4/6] fix check of mlx5_store_uidx return

Message ID 1469647047-7544-5-git-send-email-jarod@redhat.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Jarod Wilson July 27, 2016, 7:17 p.m. UTC
mlx5_store_uidx() returns an int32_t, but create_qp was storing the return
in a uint32_t, and then checking for a value less than 0, which is
impossible with the uint32_t. Use a local int32_t for the return, check
for < 0, then cast to uint32_t and save the result for later use.

CC: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
---
 src/verbs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Yishai Hadas July 28, 2016, 3:04 p.m. UTC | #1
On 7/27/2016 10:17 PM, Jarod Wilson wrote:
> mlx5_store_uidx() returns an int32_t, but create_qp was storing the return
> in a uint32_t, and then checking for a value less than 0, which is
> impossible with the uint32_t. Use a local int32_t for the return, check
> for < 0, then cast to uint32_t and save the result for later use.

Good point, thanks.

Actually the change can be to use int 'usr_idx' instead of uint32_t. See 
same flow as part of mlx5_create_xrc_srq which works as expected by 
using int.

> CC: Yishai Hadas <yishaih@mellanox.com>
> Signed-off-by: Jarod Wilson <jarod@redhat.com>
> ---
>  src/verbs.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/src/verbs.c b/src/verbs.c
> index 7ed394e..d64e406 100644
> --- a/src/verbs.c
> +++ b/src/verbs.c
> @@ -1224,11 +1224,13 @@ struct ibv_qp *create_qp(struct ibv_context *context,
>  		cmd.uidx = 0xffffff;
>  		pthread_mutex_lock(&ctx->qp_table_mutex);
>  	} else if (!is_xrc_tgt(attr->qp_type)) {
> -		usr_idx = mlx5_store_uidx(ctx, qp);
> -		if (usr_idx < 0) {
> +		int32_t uidx_ret;
> +		uidx_ret = mlx5_store_uidx(ctx, qp);
> +		if (uidx_ret < 0) {
>  			mlx5_dbg(fp, MLX5_DBG_QP, "Couldn't find free user index\n");
>  			goto err_rq_db;
>  		}
> +		usr_idx = (uint32_t)uidx_ret;
>
>  		cmd.uidx = usr_idx;
>  	}
>

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/src/verbs.c b/src/verbs.c
index 7ed394e..d64e406 100644
--- a/src/verbs.c
+++ b/src/verbs.c
@@ -1224,11 +1224,13 @@  struct ibv_qp *create_qp(struct ibv_context *context,
 		cmd.uidx = 0xffffff;
 		pthread_mutex_lock(&ctx->qp_table_mutex);
 	} else if (!is_xrc_tgt(attr->qp_type)) {
-		usr_idx = mlx5_store_uidx(ctx, qp);
-		if (usr_idx < 0) {
+		int32_t uidx_ret;
+		uidx_ret = mlx5_store_uidx(ctx, qp);
+		if (uidx_ret < 0) {
 			mlx5_dbg(fp, MLX5_DBG_QP, "Couldn't find free user index\n");
 			goto err_rq_db;
 		}
+		usr_idx = (uint32_t)uidx_ret;
 
 		cmd.uidx = usr_idx;
 	}