All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roel Kluin <roel.kluin@gmail.com>
To: swise@chelsio.com
Cc: general@lists.openfabrics.org, netdev@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] RDMA/cxgb3: test before subtraction on unsigned
Date: Tue, 03 Mar 2009 14:38:35 +0100	[thread overview]
Message-ID: <49AD32DB.20407@gmail.com> (raw)

I think there's someting wrong in iwch_post_send():

// vi drivers/infiniband/hw/cxgb3/iwch_qp.c +353
int iwch_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
                      struct ib_send_wr **bad_wr)
{
	...
        u32 num_wrs;
	...
        num_wrs = Q_FREECNT(qhp->wq.sq_rptr, qhp->wq.sq_wptr,
                  qhp->wq.sq_size_log2);
        if (num_wrs <= 0) {
                spin_unlock_irqrestore(&qhp->lock, flag);
                return -ENOMEM;
        }

// vi drivers/infiniband/hw/cxgb3/cxio_wr.h +50
#define Q_FREECNT(rptr,wptr,size_log2) ((1UL<<size_log2)-((wptr)-(rptr)))

Since num_wrs is unsigned, I think the test should occur before the subtraction,
right? please review.
------------------------------>8-------------8<---------------------------------
num_wrs is unsigned so test before the subtraction.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
diff --git a/drivers/infiniband/hw/cxgb3/iwch_qp.c b/drivers/infiniband/hw/cxgb3/iwch_qp.c
index 19661b2..1c6ebaf 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_qp.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_qp.c
@@ -369,12 +369,13 @@ int iwch_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
 		spin_unlock_irqrestore(&qhp->lock, flag);
 		return -EINVAL;
 	}
-	num_wrs = Q_FREECNT(qhp->wq.sq_rptr, qhp->wq.sq_wptr,
-		  qhp->wq.sq_size_log2);
-	if (num_wrs <= 0) {
+	if ((1UL << qhp->wq.sq_size_log2) + qhp->wq.sq_rptr <=
+			qhp->wq.sq_wptr) {
 		spin_unlock_irqrestore(&qhp->lock, flag);
 		return -ENOMEM;
 	}
+	num_wrs = Q_FREECNT(qhp->wq.sq_rptr, qhp->wq.sq_wptr,
+		  qhp->wq.sq_size_log2);
 	while (wr) {
 		if (num_wrs == 0) {
 			err = -ENOMEM;



             reply	other threads:[~2009-03-03 13:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-03 13:38 Roel Kluin [this message]
2009-03-03 15:41 ` [ofa-general] Re: [PATCH] RDMA/cxgb3: test before subtraction on unsigned Steve Wise

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49AD32DB.20407@gmail.com \
    --to=roel.kluin@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=general@lists.openfabrics.org \
    --cc=netdev@vger.kernel.org \
    --cc=swise@chelsio.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.