]> www.infradead.org Git - users/willy/xarray.git/commitdiff
memstick: Convert host IDR to IDA
authorMatthew Wilcox <willy@infradead.org>
Mon, 11 Feb 2019 21:09:07 +0000 (16:09 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:15 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/memstick/core/memstick.c

index 693ee73eb2912c05abdbfbe4955757cc767c0731..06db21d6f760871675ce5be12ab1eccd570226a6 100644 (file)
@@ -22,8 +22,7 @@ static unsigned int cmd_retries = 3;
 module_param(cmd_retries, uint, 0644);
 
 static struct workqueue_struct *workqueue;
-static DEFINE_IDR(memstick_host_idr);
-static DEFINE_SPINLOCK(memstick_host_lock);
+static DEFINE_IDA(memstick_hosts);
 
 static int memstick_dev_match(struct memstick_dev *card,
                              struct memstick_device_id *id)
@@ -509,27 +508,17 @@ EXPORT_SYMBOL(memstick_alloc_host);
  */
 int memstick_add_host(struct memstick_host *host)
 {
-       int rc;
-
-       idr_preload(GFP_KERNEL);
-       spin_lock(&memstick_host_lock);
-
-       rc = idr_alloc(&memstick_host_idr, host, 0, 0, GFP_NOWAIT);
-       if (rc >= 0)
-               host->id = rc;
+       int rc = ida_alloc(&memstick_hosts, GFP_KERNEL);
 
-       spin_unlock(&memstick_host_lock);
-       idr_preload_end();
        if (rc < 0)
                return rc;
 
+       host->id = rc;
        dev_set_name(&host->dev, "memstick%u", host->id);
 
        rc = device_add(&host->dev);
        if (rc) {
-               spin_lock(&memstick_host_lock);
-               idr_remove(&memstick_host_idr, host->id);
-               spin_unlock(&memstick_host_lock);
+               ida_free(&memstick_hosts, host->id);
                return rc;
        }
 
@@ -553,9 +542,7 @@ void memstick_remove_host(struct memstick_host *host)
        host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF);
        mutex_unlock(&host->lock);
 
-       spin_lock(&memstick_host_lock);
-       idr_remove(&memstick_host_idr, host->id);
-       spin_unlock(&memstick_host_lock);
+       ida_free(&memstick_hosts, host->id);
        device_del(&host->dev);
 }
 EXPORT_SYMBOL(memstick_remove_host);
@@ -647,7 +634,6 @@ static void __exit memstick_exit(void)
        class_unregister(&memstick_host_class);
        bus_unregister(&memstick_bus_type);
        destroy_workqueue(workqueue);
-       idr_destroy(&memstick_host_idr);
 }
 
 module_init(memstick_init);