Earlier versions of the loopback code released the per-device mutex
in-order to allow for more parallel asynchronous send/receive paths to
execute. In the interim though new variables have been added to the
struct gb_loopback{}; structure and as a result gb->send_count is now racy
w/r to the controlling sysfs interface.

This patch fixes by holding gb->mutex between gb->send_count ==
gb->iteration_max and udelay() divide - in the sending kthread. Testing on
DVT shows there's no adverse performance impact.

Signed-off-by: Bryan O'Donoghue <pure.lo...@nexus-software.ie>
---
 drivers/staging/greybus/loopback.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/greybus/loopback.c 
b/drivers/staging/greybus/loopback.c
index de17901..66f54f9 100644
--- a/drivers/staging/greybus/loopback.c
+++ b/drivers/staging/greybus/loopback.c
@@ -524,7 +524,6 @@ static int gb_loopback_async_operation(struct gb_loopback 
*gb, int type,
 
        atomic_inc(&gb->outstanding_operations);
 
-       mutex_lock(&gb->mutex);
        timeout = gb->msec_timeout;
        ret = gb_operation_request_send_async_timeout(operation, timeout,
                                                      
gb_loopback_async_operation_callback,
@@ -538,7 +537,6 @@ static int gb_loopback_async_operation(struct gb_loopback 
*gb, int type,
        gb_operation_put(operation);
        kfree(op_async);
 done:
-       mutex_unlock(&gb->mutex);
        return ret;
 }
 
@@ -918,7 +916,6 @@ static int gb_loopback_fn(void *data)
                type = gb->type;
                if (gb->ts.tv_usec == 0 && gb->ts.tv_sec == 0)
                        do_gettimeofday(&gb->ts);
-               mutex_unlock(&gb->mutex);
 
                /* Else operations to perform */
                if (gb->async) {
@@ -949,6 +946,7 @@ static int gb_loopback_fn(void *data)
                        gb_loopback_calculate_stats(gb, !!error);
                }
                gb->send_count++;
+               mutex_unlock(&gb->mutex);
                if (us_wait)
                        udelay(us_wait);
        }
-- 
2.7.4

_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to