IB/cxgb4: convert to idr_alloc()
authorTejun Heo <tj@kernel.org>
Thu, 28 Feb 2013 01:04:20 +0000 (17:04 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Feb 2013 03:10:16 +0000 (19:10 -0800)
Convert to the much saner new idr interface.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/infiniband/hw/cxgb4/iw_cxgb4.h

index 4c07fc069766ada66083f552024736d8c0574784..7eec5e13fa8c34c372659f81878b4338596ab5a0 100644 (file)
@@ -260,20 +260,21 @@ static inline int _insert_handle(struct c4iw_dev *rhp, struct idr *idr,
                                 void *handle, u32 id, int lock)
 {
        int ret;
                                 void *handle, u32 id, int lock)
 {
        int ret;
-       int newid;
 
 
-       do {
-               if (!idr_pre_get(idr, lock ? GFP_KERNEL : GFP_ATOMIC))
-                       return -ENOMEM;
-               if (lock)
-                       spin_lock_irq(&rhp->lock);
-               ret = idr_get_new_above(idr, handle, id, &newid);
-               BUG_ON(!ret && newid != id);
-               if (lock)
-                       spin_unlock_irq(&rhp->lock);
-       } while (ret == -EAGAIN);
-
-       return ret;
+       if (lock) {
+               idr_preload(GFP_KERNEL);
+               spin_lock_irq(&rhp->lock);
+       }
+
+       ret = idr_alloc(idr, handle, id, id + 1, GFP_ATOMIC);
+
+       if (lock) {
+               spin_unlock_irq(&rhp->lock);
+               idr_preload_end();
+       }
+
+       BUG_ON(ret == -ENOSPC);
+       return ret < 0 ? ret : 0;
 }
 
 static inline int insert_handle(struct c4iw_dev *rhp, struct idr *idr,
 }
 
 static inline int insert_handle(struct c4iw_dev *rhp, struct idr *idr,