From: Wei Lin Guay Date: Mon, 26 Sep 2016 14:09:27 +0000 (+0200) Subject: sif: sqflush: Fix wrong casting in the calculation of CQ full X-Git-Tag: v4.1.12-92~67^2~23 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=34ee1621fe2897e3d0a9f77ad8a88bd6a3130829;p=users%2Fjedix%2Flinux-maple.git sif: sqflush: Fix wrong casting in the calculation of CQ full Orabug: 24735772 The CQ full is calculated via last posted seq number (last_seq) minus the last completion seq number (head_seq). Both last_seq and head_seq are defined as u16. However, in the calculation to verify that the CQ is not full, a wrong casting is performed. This causes a false negative of CQ full in the wrapped case. Signed-off-by: Wei Lin Guay Reviewed-by: Knut Omang --- diff --git a/drivers/infiniband/hw/sif/sif_defs.h b/drivers/infiniband/hw/sif/sif_defs.h index 4ed1b076a4e2..a093f03f75ba 100644 --- a/drivers/infiniband/hw/sif/sif_defs.h +++ b/drivers/infiniband/hw/sif/sif_defs.h @@ -36,6 +36,7 @@ struct xchar { }; #define GREATER_16(a, b) ((s16)((s16)(a) - (s16)(b)) > 0) +#define GREATER_32(a, b) ((s32)((s32)(a) - (s32)(b)) > 0) #define LESS_OR_EQUAL_16(a, b) (!(GREATER_16((a), (b)))) #define PSIF_WC_STATUS_DUPL_COMPL_ERR (PSIF_WC_STATUS_FIELD_MAX - 1) #define PSIF_WC_STATUS_GEN_TRANSL_COMPL_ERR (PSIF_WC_STATUS_FIELD_MAX - 2) diff --git a/drivers/infiniband/hw/sif/sif_r3.c b/drivers/infiniband/hw/sif/sif_r3.c index c3c0009fdea0..948c25ffdba6 100644 --- a/drivers/infiniband/hw/sif/sif_r3.c +++ b/drivers/infiniband/hw/sif/sif_r3.c @@ -696,9 +696,9 @@ flush_sq_again: last_seq, last_gen_seq); for (; (LESS_OR_EQUAL_16(last_seq, last_gen_seq)); ++last_seq) { - if (unlikely(cq->entries < ((u32) (last_seq - sq_sw->head_seq)))) { + if (unlikely(GREATER_32((u16)(last_seq - sq_sw->head_seq), cq->entries))) { sif_log(sdev, SIF_INFO, "cq (%d) is full! (len = %d, used = %d)", - cq->index, cq->entries, last_seq - sq_sw->head_seq - 1); + cq->index, cq->entries, (u16)(last_seq - sq_sw->head_seq)); goto err_post_wa4074; }