[ofa-general] [PATCH} libmlx4: poll cq tail pointer

Eli Cohen eli at mellanox.co.il
Mon Jun 11 02:26:59 PDT 2007


cast to uint16_t is required before assigning.
Consider the following example:
wqe_index = 0, wq->tail = 0x1ffff. You'd expect wq->tail to be 0x20000
but it will actually be 0x10000. The reason for this is that compiler
upcasts the result of wqe_index - (uint16_t) wq->tail to unsigned which
yields a large number and when added to the original value of tail it
overflows and actually becomes 0x10000.

Signed-off-by: Eli Cohen <eli at mellanox.co.il>

---

diff --git a/src/cq.c b/src/cq.c
index c4a3ca4..7597a5a 100644
--- a/src/cq.c
+++ b/src/cq.c
@@ -238,7 +238,7 @@ static int mlx4_poll_one(struct mlx4_cq *cq,
 	if (is_send) {
 		wq = &(*cur_qp)->sq;
 		wqe_index = ntohs(cqe->wqe_index);
-		wq->tail += wqe_index - (uint16_t) wq->tail;
+		wq->tail += (uint16_t)(wqe_index - (uint16_t) wq->tail);
 		wc->wr_id = wq->wrid[wq->tail & (wq->max - 1)];
 		++wq->tail;
 	} else if ((*cur_qp)->ibv_qp.srq) {




More information about the general mailing list