greybus: connection: properly lock idr
We had a lock, but we never used it, so move it to be per-hd, like the
idr structure is.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c
index 07a593d..1a2bec2 100644
--- a/drivers/staging/greybus/connection.c
+++ b/drivers/staging/greybus/connection.c
@@ -78,7 +78,9 @@
struct ida *ida = &connection->hd->cport_id_map;
int id;
+ spin_lock(&connection->hd->cport_id_map_lock);
id = ida_simple_get(ida, 0, HOST_DEV_CPORT_ID_MAX, GFP_KERNEL);
+ spin_unlock(&connection->hd->cport_id_map_lock);
if (id < 0)
return false;
@@ -94,7 +96,9 @@
{
struct ida *ida = &connection->hd->cport_id_map;
+ spin_lock(&connection->hd->cport_id_map_lock);
ida_simple_remove(ida, connection->hd_cport_id);
+ spin_unlock(&connection->hd->cport_id_map_lock);
connection->hd_cport_id = CPORT_ID_BAD;
}
@@ -126,7 +130,7 @@
kfree(connection);
return NULL;
}
- connection->hd = hd; /* XXX refcount? */
+
connection->interface = interface; /* XXX refcount? */
connection->interface_cport_id = cport_id;
connection->protocol = protocol;
diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c
index 51d7e59..6c4107e 100644
--- a/drivers/staging/greybus/core.c
+++ b/drivers/staging/greybus/core.c
@@ -30,8 +30,6 @@
}
EXPORT_SYMBOL_GPL(greybus_disabled);
-static spinlock_t cport_id_map_lock;
-
static int greybus_module_match(struct device *dev, struct device_driver *drv)
{
struct greybus_driver *driver = to_greybus_driver(dev->driver);
@@ -313,6 +311,7 @@
INIT_LIST_HEAD(&hd->modules);
hd->connections = RB_ROOT;
ida_init(&hd->cport_id_map);
+ spin_lock_init(&hd->cport_id_map_lock);
return hd;
}
@@ -330,7 +329,6 @@
int retval;
BUILD_BUG_ON(HOST_DEV_CPORT_ID_MAX >= (long)CPORT_ID_BAD);
- spin_lock_init(&cport_id_map_lock);
retval = gb_debugfs_init();
if (retval) {
diff --git a/drivers/staging/greybus/greybus.h b/drivers/staging/greybus/greybus.h
index 851f5ae..20c1a03 100644
--- a/drivers/staging/greybus/greybus.h
+++ b/drivers/staging/greybus/greybus.h
@@ -186,6 +186,7 @@
struct list_head modules;
struct rb_root connections;
struct ida cport_id_map;
+ spinlock_t cport_id_map_lock;
/* Private data for the host driver */
unsigned long hd_priv[0] __attribute__ ((aligned(sizeof(s64))));