From: Greg Kroah-Hartman Date: Tue, 7 Oct 2014 03:29:40 +0000 (-0700) Subject: greybus: connection: properly lock idr X-Git-Tag: v4.9-rc1~119^2~378^2~21^2~2026 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=25b7b6d04bdfc76631cc02012f33f10bc27dd27e;p=karo-tx-linux.git 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 --- diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index 07a593d2cbd1..1a2bec22b424 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -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; diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c index 51d7e59362d5..6c4107e20762 100644 --- a/drivers/staging/greybus/core.c +++ b/drivers/staging/greybus/core.c @@ -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) { diff --git a/drivers/staging/greybus/greybus.h b/drivers/staging/greybus/greybus.h index 851f5ae095cc..20c1a034f691 100644 --- a/drivers/staging/greybus/greybus.h +++ b/drivers/staging/greybus/greybus.h @@ -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))));