memstick: convert to idr_alloc()
[~shefty/rdma-dev.git] / drivers / memstick / core / memstick.c
index 56ff19cdc2ad81ca015b9e9364318609921dcace..ffcb10ac434156adc89e4e9237d30e4ade530830 100644 (file)
@@ -512,18 +512,17 @@ int memstick_add_host(struct memstick_host *host)
 {
        int rc;
 
-       while (1) {
-               if (!idr_pre_get(&memstick_host_idr, GFP_KERNEL))
-                       return -ENOMEM;
+       idr_preload(GFP_KERNEL);
+       spin_lock(&memstick_host_lock);
 
-               spin_lock(&memstick_host_lock);
-               rc = idr_get_new(&memstick_host_idr, host, &host->id);
-               spin_unlock(&memstick_host_lock);
-               if (!rc)
-                       break;
-               else if (rc != -EAGAIN)
-                       return rc;
-       }
+       rc = idr_alloc(&memstick_host_idr, host, 0, 0, GFP_NOWAIT);
+       if (rc >= 0)
+               host->id = rc;
+
+       spin_unlock(&memstick_host_lock);
+       idr_preload_end();
+       if (rc < 0)
+               return rc;
 
        dev_set_name(&host->dev, "memstick%u", host->id);