]> www.infradead.org Git - users/willy/xarray.git/commitdiff
tifm: Convert to IDA
authorMatthew Wilcox <willy@infradead.org>
Tue, 12 Feb 2019 21:20:07 +0000 (16:20 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:16 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/misc/tifm_core.c

index 667e574a7df2a45b72942ee50d5b7925e62b3a34..3dd00f072b997e43e752f999c37dab4d419cdcab 100644 (file)
@@ -15,8 +15,7 @@
 #define DRIVER_VERSION "0.8"
 
 static struct workqueue_struct *workqueue;
-static DEFINE_IDR(tifm_adapter_idr);
-static DEFINE_SPINLOCK(tifm_adapter_lock);
+static DEFINE_IDA(tifm_adapter_ids);
 
 static const char *tifm_media_type_name(unsigned char type, unsigned char nt)
 {
@@ -192,25 +191,15 @@ EXPORT_SYMBOL(tifm_alloc_adapter);
 
 int tifm_add_adapter(struct tifm_adapter *fm)
 {
-       int rc;
+       int rc = ida_alloc(&tifm_adapter_ids, GFP_KERNEL);
 
-       idr_preload(GFP_KERNEL);
-       spin_lock(&tifm_adapter_lock);
-       rc = idr_alloc(&tifm_adapter_idr, fm, 0, 0, GFP_NOWAIT);
-       if (rc >= 0)
-               fm->id = rc;
-       spin_unlock(&tifm_adapter_lock);
-       idr_preload_end();
        if (rc < 0)
                return rc;
-
+       fm->id = rc;
        dev_set_name(&fm->dev, "tifm%u", fm->id);
        rc = device_add(&fm->dev);
-       if (rc) {
-               spin_lock(&tifm_adapter_lock);
-               idr_remove(&tifm_adapter_idr, fm->id);
-               spin_unlock(&tifm_adapter_lock);
-       }
+       if (rc)
+               ida_free(&tifm_adapter_ids, fm->id);
 
        return rc;
 }
@@ -226,9 +215,7 @@ void tifm_remove_adapter(struct tifm_adapter *fm)
                        device_unregister(&fm->sockets[cnt]->dev);
        }
 
-       spin_lock(&tifm_adapter_lock);
-       idr_remove(&tifm_adapter_idr, fm->id);
-       spin_unlock(&tifm_adapter_lock);
+       ida_free(&tifm_adapter_ids, fm->id);
        device_del(&fm->dev);
 }
 EXPORT_SYMBOL(tifm_remove_adapter);