/**
* 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.
*/
struct ac97_controller {
const struct ac97_controller_ops *ops;
- struct list_head controllers;
struct device adap;
int nr;
unsigned short slots_available;
#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>
#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;
{
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);
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));
}
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;
if (ret)
put_device(&ac97_ctrl->adap);
}
- if (!ret)
- list_add(&ac97_ctrl->controllers, &ac97_controllers);
mutex_unlock(&ac97_controllers_mutex);
if (!ret)