usb: gadget: f_mass_storage: add missing memory barrier for thread_wakeup_needed
authorUCHINO Satoshi <satoshi.uchino@toshiba.co.jp>
Thu, 23 May 2013 02:10:11 +0000 (11:10 +0900)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 27 Jul 2013 04:34:08 +0000 (05:34 +0100)
commit d68c277b501889b3a50c179d1c3d704db7947b83 upstream.

Without this memory barrier, the file-storage thread may fail to
escape from the following while loop, because it may observe new
common->thread_wakeup_needed and old bh->state which are updated by
the callback functions.

/* Wait for the CBW to arrive */
while (bh->state != BUF_STATE_FULL) {
rc = sleep_thread(common);
if (rc)
return rc;
}

Signed-off-by: UCHINO Satoshi <satoshi.uchino@toshiba.co.jp>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/usb/gadget/f_mass_storage.c

index a5570b6..8d7fb6b 100644 (file)
@@ -512,6 +512,7 @@ static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
 /* Caller must hold fsg->lock */
 static void wakeup_thread(struct fsg_common *common)
 {
+       smp_wmb();      /* ensure the write of bh->state is complete */
        /* Tell the main thread that something has happened */
        common->thread_wakeup_needed = 1;
        if (common->thread_task)
@@ -731,6 +732,7 @@ static int sleep_thread(struct fsg_common *common)
        }
        __set_current_state(TASK_RUNNING);
        common->thread_wakeup_needed = 0;
+       smp_rmb();      /* ensure the latest bh->state is visible */
        return rc;
 }