greybus: connection: properly lock idr
authorGreg Kroah-Hartman <greg@kroah.com>
Tue, 7 Oct 2014 03:29:40 +0000 (20:29 -0700)
committerGreg Kroah-Hartman <greg@kroah.com>
Tue, 7 Oct 2014 03:29:40 +0000 (20:29 -0700)
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>
drivers/staging/greybus/connection.c
drivers/staging/greybus/core.c
drivers/staging/greybus/greybus.h

index 07a593d..1a2bec2 100644 (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;
index 51d7e59..6c4107e 100644 (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) {
index 851f5ae..20c1a03 100644 (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))));