aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/greybus/module.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <greg@kroah.com>2014-12-24 13:01:46 -0800
committerGreg Kroah-Hartman <greg@kroah.com>2015-01-02 13:05:42 -0800
commite5646710c1836abb038415d3009f1c72d6794b77 (patch)
treeaa6fab744f389401f859e8bab4c8a8306729560d /drivers/staging/greybus/module.c
parentgreybus: i2c-gb: move i2c protocol into the gpbridge driver (diff)
downloadlinux-dev-e5646710c1836abb038415d3009f1c72d6794b77.tar.xz
linux-dev-e5646710c1836abb038415d3009f1c72d6794b77.zip
greybus: module: get rid of global list of modules
Use the list that the driver core keeps of our structure, no need to duplicate it with a local list as well. This gets rid of a static lock too, always a nice thing to do. Signed-off-by: Greg Kroah-Hartman <greg@kroah.com> Reviewed-by: Alex Elder <elder@linaro.org>
Diffstat (limited to 'drivers/staging/greybus/module.c')
-rw-r--r--drivers/staging/greybus/module.c49
1 files changed, 22 insertions, 27 deletions
diff --git a/drivers/staging/greybus/module.c b/drivers/staging/greybus/module.c
index 625e2d436073..56a55fea107b 100644
--- a/drivers/staging/greybus/module.c
+++ b/drivers/staging/greybus/module.c
@@ -10,14 +10,6 @@
#include "greybus.h"
-/*
- * List of modules in the system. We really should just walk the list the
- * driver core provides us, but as we have lots of different things on the same
- * "bus" at the same time, a single list of modules is simplest for now.
- */
-static DEFINE_SPINLOCK(gb_modules_lock);
-static LIST_HEAD(module_list);
-
/* module sysfs attributes */
#define gb_module_attr(field, type) \
static ssize_t field##_show(struct device *dev, \
@@ -58,10 +50,6 @@ static void greybus_module_release(struct device *dev)
{
struct gb_module *module = to_gb_module(dev);
- spin_lock(&gb_modules_lock);
- list_del(&module->list);
- spin_unlock(&gb_modules_lock);
-
kfree(module);
}
@@ -70,24 +58,35 @@ struct device_type greybus_module_type = {
.release = greybus_module_release,
};
+static int module_find(struct device *dev, void *data)
+{
+ struct gb_module *module;
+ u8 *module_id = data;
+
+ if (!is_gb_module(dev))
+ return 0;
+
+ module = to_gb_module(dev);
+ if (module->module_id == *module_id)
+ return 1;
+
+ return 0;
+}
+
/*
* Search the list of modules in the system. If one is found, return it, with
* the reference count incremented.
*/
static struct gb_module *gb_module_find(u8 module_id)
{
- struct gb_module *module;
+ struct device *dev;
+ struct gb_module *module = NULL;
+
+ dev = bus_find_device(&greybus_bus_type, NULL,
+ &module_id, module_find);
+ if (dev)
+ module = to_gb_module(dev);
- spin_lock(&gb_modules_lock);
- list_for_each_entry(module, &module_list, list) {
- if (module->module_id == module_id) {
- get_device(&module->dev);
- goto exit;
- }
- }
- module = NULL;
-exit:
- spin_unlock(&gb_modules_lock);
return module;
}
@@ -119,10 +118,6 @@ static struct gb_module *gb_module_create(struct greybus_host_device *hd,
return NULL;
}
- spin_lock(&gb_modules_lock);
- list_add_tail(&module->list, &module_list);
- spin_unlock(&gb_modules_lock);
-
return module;
}