greybus: loopback: hold a coarse lock while init/exit run
authorBryan O'Donoghue <bryan.odonoghue@linaro.org>
Mon, 14 Sep 2015 09:48:40 +0000 (10:48 +0100)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 15 Sep 2015 04:35:58 +0000 (21:35 -0700)
This patch holds gb_dev.mutex for the duration of init and exit to reduce
complexity while ensuring that init and exit run atomically with respect
to slave threads @ gb_loopback_fn().

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/loopback.c

index 33c21cf..7e1f527 100644 (file)
@@ -864,21 +864,18 @@ static int gb_loopback_connection_init(struct gb_connection *connection)
                                    gb_dev.root, &gb_dev,
                                    &gb_loopback_debugfs_dev_latency_ops);
                retval = sysfs_create_groups(kobj, loopback_dev_groups);
-               if (retval) {
-                       mutex_unlock(&gb_dev.mutex);
+               if (retval)
                        goto out_sysfs;
-               }
+
                /* Calculate maximum payload */
                gb_dev.size_max = gb_operation_get_payload_size_max(connection);
                if (gb_dev.size_max <=
                        sizeof(struct gb_loopback_transfer_request)) {
                        retval = -EINVAL;
-                       mutex_unlock(&gb_dev.mutex);
                        goto out_sysfs;
                }
                gb_dev.size_max -= sizeof(struct gb_loopback_transfer_request);
        }
-       mutex_unlock(&gb_dev.mutex);
 
        /* Create per-connection sysfs and debugfs data-points */
        snprintf(name, sizeof(name), "raw_latency_endo0:%d:%d:%d:%d",
@@ -916,10 +913,9 @@ static int gb_loopback_connection_init(struct gb_connection *connection)
                goto out_kfifo1;
        }
 
-       mutex_lock(&gb_dev.mutex);
        list_add_tail(&gb->entry, &gb_dev.list);
-       mutex_unlock(&gb_dev.mutex);
        gb_dev.count++;
+       mutex_unlock(&gb_dev.mutex);
        return 0;
 
 out_kfifo1:
@@ -934,6 +930,7 @@ out_sysfs_dev:
        debugfs_remove(gb->file);
        connection->private = NULL;
 out_sysfs:
+       mutex_unlock(&gb_dev.mutex);
        kfree(gb);
 
        return retval;