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>
This commit is contained in:
Greg Kroah-Hartman 2014-10-06 20:29:40 -07:00
parent ff8aed5274
commit 25b7b6d04b
3 changed files with 7 additions and 4 deletions

View file

@ -78,7 +78,9 @@ static bool gb_connection_hd_cport_id_alloc(struct gb_connection *connection)
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 @@ static void gb_connection_hd_cport_id_free(struct gb_connection *connection)
{
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 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface,
kfree(connection);
return NULL;
}
connection->hd = hd; /* XXX refcount? */
connection->interface = interface; /* XXX refcount? */
connection->interface_cport_id = cport_id;
connection->protocol = protocol;

View file

@ -30,8 +30,6 @@ int greybus_disabled(void)
}
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 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver
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 @@ static int __init gb_init(void)
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) {

View file

@ -186,6 +186,7 @@ struct greybus_host_device {
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))));