]> www.infradead.org Git - users/willy/xarray.git/commitdiff
ac97: Convert ac97_adapter_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Mon, 18 Feb 2019 14:49:21 +0000 (09:49 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:17 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
include/sound/ac97/controller.h
sound/ac97/bus.c

index 06b5afb7fa6b9fedfd997a1e87634012470ce9c4..64d8bdf687905a1d4373652637b2f1c3d05d9f09 100644 (file)
@@ -17,7 +17,6 @@ struct ac97_controller_ops;
 /**
  * struct ac97_controller - The AC97 controller of the AC-Link
  * @ops:               the AC97 operations.
- * @controllers:       linked list of all existing controllers.
  * @adap:              the shell device ac97-%d, ie. ac97 adapter
  * @nr:                        the number of the shell device
  * @slots_available:   the mask of accessible/scanable codecs.
@@ -30,7 +29,6 @@ struct ac97_controller_ops;
  */
 struct ac97_controller {
        const struct ac97_controller_ops *ops;
-       struct list_head controllers;
        struct device adap;
        int nr;
        unsigned short slots_available;
index 7985dd8198b6c4ae066d38041aeb3d45c6947ab8..fae3668f4401631746ad51c470977158c83da7d5 100644 (file)
@@ -7,7 +7,6 @@
 #include <linux/bitops.h>
 #include <linux/clk.h>
 #include <linux/device.h>
-#include <linux/idr.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
 #include <linux/of.h>
@@ -15,6 +14,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/slab.h>
 #include <linux/sysfs.h>
+#include <linux/xarray.h>
 #include <sound/ac97/codec.h>
 #include <sound/ac97/controller.h>
 #include <sound/ac97/regs.h>
 #include "ac97_core.h"
 
 /*
- * Protects ac97_controllers and each ac97_controller structure.
+ * Protects each ac97_controller structure.
  */
 static DEFINE_MUTEX(ac97_controllers_mutex);
-static DEFINE_IDR(ac97_adapter_idr);
-static LIST_HEAD(ac97_controllers);
+static DEFINE_XARRAY_ALLOC(ac97_adapters);
 
 static struct bus_type ac97_bus_type;
 
@@ -287,7 +286,6 @@ static void ac97_del_adapter(struct ac97_controller *ac97_ctrl)
 {
        mutex_lock(&ac97_controllers_mutex);
        ac97_ctrl_codecs_unregister(ac97_ctrl);
-       list_del(&ac97_ctrl->controllers);
        mutex_unlock(&ac97_controllers_mutex);
 
        device_unregister(&ac97_ctrl->adap);
@@ -298,7 +296,7 @@ static void ac97_adapter_release(struct device *dev)
        struct ac97_controller *ac97_ctrl;
 
        ac97_ctrl = to_ac97_controller(dev);
-       idr_remove(&ac97_adapter_idr, ac97_ctrl->nr);
+       xa_erase(&ac97_adapters, ac97_ctrl->nr);
        dev_dbg(&ac97_ctrl->adap, "adapter unregistered by %s\n",
                dev_name(ac97_ctrl->parent));
 }
@@ -313,8 +311,8 @@ static int ac97_add_adapter(struct ac97_controller *ac97_ctrl)
        int ret;
 
        mutex_lock(&ac97_controllers_mutex);
-       ret = idr_alloc(&ac97_adapter_idr, ac97_ctrl, 0, 0, GFP_KERNEL);
-       ac97_ctrl->nr = ret;
+       ret = xa_alloc(&ac97_adapters, &ac97_ctrl->nr, ac97_ctrl,
+                       xa_limit_32b, GFP_KERNEL);
        if (ret >= 0) {
                dev_set_name(&ac97_ctrl->adap, "ac97-%d", ret);
                ac97_ctrl->adap.type = &ac97_adapter_type;
@@ -323,8 +321,6 @@ static int ac97_add_adapter(struct ac97_controller *ac97_ctrl)
                if (ret)
                        put_device(&ac97_ctrl->adap);
        }
-       if (!ret)
-               list_add(&ac97_ctrl->controllers, &ac97_controllers);
        mutex_unlock(&ac97_controllers_mutex);
 
        if (!ret)