Commit 64044bcf authored by Roland Dreier's avatar Roland Dreier

[IB] mthca: fix wraparound handling in mthca_cq_clean()

Handle case where prod_index has wrapped around and become less than
cq->cons_index by checking that their difference as a signed int is
positive rather than comparing directly.
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent 62abb841
...@@ -258,7 +258,7 @@ void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn, ...@@ -258,7 +258,7 @@ void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn,
{ {
struct mthca_cq *cq; struct mthca_cq *cq;
struct mthca_cqe *cqe; struct mthca_cqe *cqe;
int prod_index; u32 prod_index;
int nfreed = 0; int nfreed = 0;
spin_lock_irq(&dev->cq_table.lock); spin_lock_irq(&dev->cq_table.lock);
...@@ -293,19 +293,15 @@ void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn, ...@@ -293,19 +293,15 @@ void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn,
* Now sweep backwards through the CQ, removing CQ entries * Now sweep backwards through the CQ, removing CQ entries
* that match our QP by copying older entries on top of them. * that match our QP by copying older entries on top of them.
*/ */
while (prod_index > cq->cons_index) { while ((int) --prod_index - (int) cq->cons_index >= 0) {
cqe = get_cqe(cq, (prod_index - 1) & cq->ibcq.cqe); cqe = get_cqe(cq, prod_index & cq->ibcq.cqe);
if (cqe->my_qpn == cpu_to_be32(qpn)) { if (cqe->my_qpn == cpu_to_be32(qpn)) {
if (srq) if (srq)
mthca_free_srq_wqe(srq, be32_to_cpu(cqe->wqe)); mthca_free_srq_wqe(srq, be32_to_cpu(cqe->wqe));
++nfreed; ++nfreed;
} } else if (nfreed)
else if (nfreed) memcpy(get_cqe(cq, (prod_index + nfreed) & cq->ibcq.cqe),
memcpy(get_cqe(cq, (prod_index - 1 + nfreed) & cqe, MTHCA_CQ_ENTRY_SIZE);
cq->ibcq.cqe),
cqe,
MTHCA_CQ_ENTRY_SIZE);
--prod_index;
} }
if (nfreed) { if (nfreed) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment