IB/core: convert to idr_alloc()
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / infiniband / core / cma.c
index d789eea32168788439e378edcdc33d75c4ce693f..c32eeaa3f3b14ff1514b3eb9a8c94e19164ca436 100644 (file)
@@ -2143,33 +2143,23 @@ static int cma_alloc_port(struct idr *ps, struct rdma_id_private *id_priv,
                          unsigned short snum)
 {
        struct rdma_bind_list *bind_list;
-       int port, ret;
+       int ret;
 
        bind_list = kzalloc(sizeof *bind_list, GFP_KERNEL);
        if (!bind_list)
                return -ENOMEM;
 
-       do {
-               ret = idr_get_new_above(ps, bind_list, snum, &port);
-       } while ((ret == -EAGAIN) && idr_pre_get(ps, GFP_KERNEL));
-
-       if (ret)
-               goto err1;
-
-       if (port != snum) {
-               ret = -EADDRNOTAVAIL;
-               goto err2;
-       }
+       ret = idr_alloc(ps, bind_list, snum, snum + 1, GFP_KERNEL);
+       if (ret < 0)
+               goto err;
 
        bind_list->ps = ps;
-       bind_list->port = (unsigned short) port;
+       bind_list->port = (unsigned short)ret;
        cma_bind_port(bind_list, id_priv);
        return 0;
-err2:
-       idr_remove(ps, port);
-err1:
+err:
        kfree(bind_list);
-       return ret;
+       return ret == -ENOSPC ? -EADDRNOTAVAIL : ret;
 }
 
 static int cma_alloc_any_port(struct idr *ps, struct rdma_id_private *id_priv)