Skip to contentSkip to conversation

infiniband: cxgb3: fix signed bug

PATCH In review Dan Carpenter 3 participants 5 messages Jul 17, 2010 – Jul 21, 2010 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 infiniband: cxgb3: fix signed bug

"num_wrs" should be signed so that the "if (num_wrs <= 0)" checks work.

drivers/infiniband/hw/cxgb3/iwch_qp.c +3 -3
index ae47bfd..e90fb2d 100644
@@ -357,7 +357,7 @@ int iwch_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
 	struct iwch_qp *qhp;
 	u32 idx;
 	union t3_wr *wqe;
-	u32 num_wrs;
+	int num_wrs;
 	unsigned long flag;
 	struct t3_swsq *sqp;
 	int wr_cnt = 1;
@@ -535,7 +535,7 @@ int iwch_bind_mw(struct ib_qp *qp,
 	union t3_wr *wqe;
 	u32 pbl_addr;
 	u8 page_size;
-	u32 num_wrs;
+	int num_wrs;
 	unsigned long flag;
 	struct ib_sge sgl;
 	int err=0;
@@ -554,7 +554,7 @@ int iwch_bind_mw(struct ib_qp *qp,
 	}
 	num_wrs = Q_FREECNT(qhp->wq.sq_rptr, qhp->wq.sq_wptr,
 			    qhp->wq.sq_size_log2);
-	if ((num_wrs) <= 0) {
+	if (num_wrs <= 0) {
 		spin_unlock_irqrestore(&qhp->lock, flag);
 		return -ENOMEM;
 	}
#1 lore raw
Quoted 28 lines · Dan Carpenter

"num_wrs" should be signed so that the "if (num_wrs <= 0)" checks work.

drivers/infiniband/hw/cxgb3/iwch_qp.c +2 -2
index ae47bfd..e90fb2d 100644
@@ -357,7 +357,7 @@ int iwch_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
 	struct iwch_qp *qhp;
 	u32 idx;
 	union t3_wr *wqe;
-	u32 num_wrs;
+	int num_wrs;
 	unsigned long flag;
 	struct t3_swsq *sqp;
 	int wr_cnt = 1;
@@ -535,7 +535,7 @@ int iwch_bind_mw(struct ib_qp *qp,
 	union t3_wr *wqe;
 	u32 pbl_addr;
 	u8 page_size;
-	u32 num_wrs;
+	int num_wrs;
 	unsigned long flag;
 	struct ib_sge sgl;
 	int err=0;

drivers/infiniband/hw/cxgb3/iwch_qp.c int iwch_bind_mw(struct ib_qp *qp, · line 560

Quoted 8 lines
drivers/infiniband/hw/cxgb3/iwch_qp.c +1 -1
@@ -554,7 +554,7 @@ int iwch_bind_mw(struct ib_qp *qp,
 	}
 	num_wrs = Q_FREECNT(qhp->wq.sq_rptr, qhp->wq.sq_wptr,
 			    qhp->wq.sq_size_log2);
-	if ((num_wrs) <= 0) {
+	if (num_wrs <= 0) {
 		spin_unlock_irqrestore(&qhp->lock, flag);
 		return -ENOMEM;
 	}

The macro Q_FREECNT() must never return <0 or things are badly broken, so this patch should really leave num_wrs as unsigned and just check for num_wrs = 0.

Steve.

A message that is not in the archive (sent off-list or not yet received): 4C446509.3010400-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org

#3 lore raw

PATCH v2 1/1 infiniband: cxgb3: clean up signed check

Q_FREECNT() returns the number of spaces free. This should never be a negative amount. Also the num_wrs is an unsigned int so it can never be less than zero.

---
In v1: I changed num_wrs to a signed int.

drivers/infiniband/hw/cxgb3/iwch_qp.c +2 -2
index ae47bfd..6adc13f 100644
@@ -371,7 +371,7 @@ int iwch_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
 	}
 	num_wrs = Q_FREECNT(qhp->wq.sq_rptr, qhp->wq.sq_wptr,
 		  qhp->wq.sq_size_log2);
-	if (num_wrs <= 0) {
+	if (num_wrs = 0) {
 		spin_unlock_irqrestore(&qhp->lock, flag);
 		err = -ENOMEM;
 		goto out;
@@ -554,7 +554,7 @@ int iwch_bind_mw(struct ib_qp *qp,
 	}
 	num_wrs = Q_FREECNT(qhp->wq.sq_rptr, qhp->wq.sq_wptr,
 			    qhp->wq.sq_size_log2);
-	if ((num_wrs) <= 0) {
+	if (num_wrs = 0) {
 		spin_unlock_irqrestore(&qhp->lock, flag);
 		return -ENOMEM;
 	}
Acked-by on v2 1/1
#4 lore raw

Re: [patch v2] infiniband: cxgb3: clean up signed check

Quoted 35 lines · Dan Carpenter

Q_FREECNT() returns the number of spaces free. This should never be a negative amount. Also the num_wrs is an unsigned int so it can never be less than zero.

---
In v1: I changed num_wrs to a signed int.

drivers/infiniband/hw/cxgb3/iwch_qp.c +2 -3
index ae47bfd..6adc13f 100644
@@ -371,7 +371,7 @@ int iwch_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
 	}
 	num_wrs = Q_FREECNT(qhp->wq.sq_rptr, qhp->wq.sq_wptr,
 		  qhp->wq.sq_size_log2);
-	if (num_wrs <= 0) {
+	if (num_wrs = 0) {
 		spin_unlock_irqrestore(&qhp->lock, flag);
 		err = -ENOMEM;
 		goto out;
@@ -554,7 +554,7 @@ int iwch_bind_mw(struct ib_qp *qp,
 	}
 	num_wrs = Q_FREECNT(qhp->wq.sq_rptr, qhp->wq.sq_wptr,
 			    qhp->wq.sq_size_log2);
-	if ((num_wrs) <= 0) {
+	if (num_wrs = 0) {
 		spin_unlock_irqrestore(&qhp->lock, flag);
 		return -ENOMEM;
 	}
--

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