Use for_each_set_bit() and for_each_set_bit_from() to iterate over all
the set bit in a memory region.

Signed-off-by: Akinobu Mita <[email protected]>
Cc: Roland Dreier <[email protected]>
Cc: Sean Hefty <[email protected]>
Cc: Hal Rosenstock <[email protected]>
Cc: Mike Marciniszyn <[email protected]>
Cc: [email protected]
---
 drivers/infiniband/hw/qib/qib_file_ops.c |   22 ++++------------------
 drivers/infiniband/hw/qib/qib_tx.c       |   14 +++++---------
 2 files changed, 9 insertions(+), 27 deletions(-)

diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c 
b/drivers/infiniband/hw/qib/qib_file_ops.c
index a740324..7c901d9 100644
--- a/drivers/infiniband/hw/qib/qib_file_ops.c
+++ b/drivers/infiniband/hw/qib/qib_file_ops.c
@@ -399,10 +399,7 @@ cleanup:
                if (limit > tidcnt)
                        /* just in case size changes in future */
                        limit = tidcnt;
-               tid = find_first_bit((const unsigned long *)tidmap, limit);
-               for (; tid < limit; tid++) {
-                       if (!test_bit(tid, tidmap))
-                               continue;
+               for_each_set_bit(tid, tidmap, limit) {
                        if (dd->pageshadow[ctxttid + tid]) {
                                dma_addr_t phys;
 
@@ -504,17 +501,8 @@ static int qib_tid_free(struct qib_ctxtdata *rcd, unsigned 
subctxt,
        if (limit > tidcnt)
                /* just in case size changes in future */
                limit = tidcnt;
-       tid = find_first_bit(tidmap, limit);
-       for (cnt = 0; tid < limit; tid++) {
-               /*
-                * small optimization; if we detect a run of 3 or so without
-                * any set, use find_first_bit again.  That's mainly to
-                * accelerate the case where we wrapped, so we have some at
-                * the beginning, and some at the end, and a big gap
-                * in the middle.
-                */
-               if (!test_bit(tid, tidmap))
-                       continue;
+       cnt = 0;
+       for_each_set_bit(tid, tidmap, limit) {
                cnt++;
                if (dd->pageshadow[ctxttid + tid]) {
                        struct page *p;
@@ -1948,9 +1936,7 @@ static int qib_user_event_ack(struct qib_ctxtdata *rcd, 
int subctxt,
 {
        int ret = 0, i;
 
-       for (i = 0; i <= _QIB_MAX_EVENT_BIT; i++) {
-               if (!test_bit(i, &events))
-                       continue;
+       for_each_set_bit(i, &events, _QIB_MAX_EVENT_BIT + 1) {
                if (i == _QIB_EVENT_DISARM_BUFS_BIT) {
                        (void)qib_disarm_piobufs_ifneeded(rcd);
                        ret = disarm_req_delay(rcd);
diff --git a/drivers/infiniband/hw/qib/qib_tx.c 
b/drivers/infiniband/hw/qib/qib_tx.c
index 1bf626c..93d236a 100644
--- a/drivers/infiniband/hw/qib/qib_tx.c
+++ b/drivers/infiniband/hw/qib/qib_tx.c
@@ -82,7 +82,6 @@ int qib_disarm_piobufs_ifneeded(struct qib_ctxtdata *rcd)
        struct qib_devdata *dd = rcd->dd;
        unsigned i;
        unsigned last;
-       unsigned n = 0;
 
        last = rcd->pio_base + rcd->piocnt;
        /*
@@ -101,11 +100,10 @@ int qib_disarm_piobufs_ifneeded(struct qib_ctxtdata *rcd)
                                  &rcd->user_event_mask[i]);
        }
        spin_lock_irq(&dd->pioavail_lock);
-       for (i = rcd->pio_base; i < last; i++) {
-               if (__test_and_clear_bit(i, dd->pio_need_disarm)) {
-                       n++;
-                       dd->f_sendctrl(rcd->ppd, QIB_SENDCTRL_DISARM_BUF(i));
-               }
+       i = rcd->pio_base;
+       for_each_set_bit_from(i, dd->pio_need_disarm, last) {
+               __clear_bit(i, dd->pio_need_disarm);
+               dd->f_sendctrl(rcd->ppd, QIB_SENDCTRL_DISARM_BUF(i));
        }
        spin_unlock_irq(&dd->pioavail_lock);
        return 0;
@@ -178,10 +176,8 @@ void qib_disarm_piobufs_set(struct qib_devdata *dd, 
unsigned long *mask,
        for (i = 0; i < dd->num_pports; i++)
                pppd[i] = NULL;
 
-       for (i = 0; i < cnt; i++) {
+       for_each_set_bit(i, mask, cnt) {
                int which;
-               if (!test_bit(i, mask))
-                       continue;
                /*
                 * If the buffer is owned by the DMA hardware,
                 * reset the DMA engine.
-- 
1.7.4.4

--
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

Reply via email to