summaryrefslogtreecommitdiff
path: root/tools/lib/python
diff options
context:
space:
mode:
authorYishai Hadas <yishaih@nvidia.com>2026-09-15 18:33:28 +0300
committerLeon Romanovsky <leon@kernel.org>2026-09-22 09:14:44 -0400
commitc6aa5feb52106664df44ef3c8c1da48f703ef8f0 (patch)
tree8c074cc14adbb49bc19cec74e68c1063941bedb9 /tools/lib/python
parent8a8088b899e4cdfe558428cd6113d45df81625be (diff)
RDMA/mlx5: Use unsigned comparison in the CQ cleanup loop
__mlx5_ib_cq_clean() sweeps the CQ backwards from the producer index down to the consumer index: while ((int) --prod_index - (int) cq->mcq.cons_index >= 0) Both indexes are free running u32 counters, so the comparison has to be done modulo 2^32. Casting each operand to int and subtracting does not do that: the subtraction overflows whenever the two indexes straddle 2^31, which is undefined behaviour, and a compiler that assumes signed overflow cannot occur is free to discard the subtraction and fold the expression into a plain signed comparison. That comparison is not wraparound safe. The kernel is built with -fno-strict-overflow, so gcc and clang both retain the subtraction today and the generated code is unaffected; there is no known user-visible impact from the current code. Still, correctness here shouldn't depend on that build flag. Replace the loop with a plain unsigned equality check instead. while (prod_index != cq->mcq.cons_index) { --prod_index; ... The preceding forward scan starts prod_index at cons_index and stops no later than cons_index + cq->ibcq.cqe, so the two indexes are at most cq->ibcq.cqe apart. Decrementing prod_index reaches cons_index in exactly that many iterations regardless of whether either counter has wrapped, because the loop no longer compares magnitudes at all. Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Signed-off-by: Edward Srouji <edwards@nvidia.com> Link: https://patch.msgid.link/20260915-fix-cq-cleanup-v1-1-e991944cf898@nvidia.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
Diffstat (limited to 'tools/lib/python')
0 files changed, 0 insertions, 0 deletions