]> www.infradead.org Git - users/willy/xarray.git/commitdiff
dca: Convert dca_idr to IDA
authorMatthew Wilcox <willy@infradead.org>
Sat, 3 Nov 2018 03:17:29 +0000 (23:17 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:14 +0000 (21:38 -0400)
The DCA code never looks up the pointer it stores in the IDR, so it
can use the IDA which is more efficient and easier to use.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/dca/dca-sysfs.c

index eb25627b059dc3dbcbdf48ddedbdc50614bf1228..e8979e61d255c0ab7c7be110cf5558aeb001435e 100644 (file)
@@ -14,8 +14,7 @@
 #include <linux/export.h>
 
 static struct class *dca_class;
-static struct idr dca_idr;
-static spinlock_t dca_idr_lock;
+static DEFINE_IDA(providers);
 
 int dca_sysfs_add_req(struct dca_provider *dca, struct device *dev, int slot)
 {
@@ -39,23 +38,14 @@ int dca_sysfs_add_provider(struct dca_provider *dca, struct device *dev)
        struct device *cd;
        int ret;
 
-       idr_preload(GFP_KERNEL);
-       spin_lock(&dca_idr_lock);
-
-       ret = idr_alloc(&dca_idr, dca, 0, 0, GFP_NOWAIT);
-       if (ret >= 0)
-               dca->id = ret;
-
-       spin_unlock(&dca_idr_lock);
-       idr_preload_end();
+       ret = ida_alloc(&providers, GFP_KERNEL);
        if (ret < 0)
                return ret;
+       dca->id = ret;
 
        cd = device_create(dca_class, dev, MKDEV(0, 0), NULL, "dca%d", dca->id);
        if (IS_ERR(cd)) {
-               spin_lock(&dca_idr_lock);
-               idr_remove(&dca_idr, dca->id);
-               spin_unlock(&dca_idr_lock);
+               ida_free(&providers, dca->id);
                return PTR_ERR(cd);
        }
        dca->cd = cd;
@@ -66,27 +56,16 @@ void dca_sysfs_remove_provider(struct dca_provider *dca)
 {
        device_unregister(dca->cd);
        dca->cd = NULL;
-       spin_lock(&dca_idr_lock);
-       idr_remove(&dca_idr, dca->id);
-       spin_unlock(&dca_idr_lock);
+       ida_free(&providers, dca->id);
 }
 
 int __init dca_sysfs_init(void)
 {
-       idr_init(&dca_idr);
-       spin_lock_init(&dca_idr_lock);
-
        dca_class = class_create(THIS_MODULE, "dca");
-       if (IS_ERR(dca_class)) {
-               idr_destroy(&dca_idr);
-               return PTR_ERR(dca_class);
-       }
-       return 0;
+       return PTR_ERR_OR_ZERO(dca_class);
 }
 
 void __exit dca_sysfs_exit(void)
 {
        class_destroy(dca_class);
-       idr_destroy(&dca_idr);
 }
-