Skip to content

Commit efb6b53

Browse files
Uttkarsh Aggarwalgregkh
authored andcommitted
usb: gadget: f_fs: Add unbind event before functionfs_unbind
While exercising the unbind path, with the current implementation the functionfs_unbind would be calling which waits for the ffs->mutex to be available, however within the same time ffs_ep0_read is invoked & if no setup packets are pending, it will invoke function wait_event_interruptible_exclusive_locked_irq which by definition waits for the ev.count to be increased inside the same mutex for which functionfs_unbind is waiting. This creates deadlock situation because the functionfs_unbind won't get the lock until ev.count is increased which can only happen if the caller ffs_func_unbind can proceed further. Following is the illustration: CPU1 CPU2 ffs_func_unbind() ffs_ep0_read() mutex_lock(ffs->mutex) wait_event(ffs->ev.count) functionfs_unbind() mutex_lock(ffs->mutex) mutex_unlock(ffs->mutex) ffs_event_add() <deadlock> Fix this by moving the event unbind before functionfs_unbind to ensure the ev.count is incrased properly. Fixes: 6a19da1 ("usb: gadget: f_fs: Prevent race during ffs_ep0_queue_wait") Cc: stable <[email protected]> Signed-off-by: Uttkarsh Aggarwal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent dbe678f commit efb6b53

File tree

1 file changed

+1
-1
lines changed
  • drivers/usb/gadget/function

1 file changed

+1
-1
lines changed

drivers/usb/gadget/function/f_fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3535,6 +3535,7 @@ static void ffs_func_unbind(struct usb_configuration *c,
35353535
/* Drain any pending AIO completions */
35363536
drain_workqueue(ffs->io_completion_wq);
35373537

3538+
ffs_event_add(ffs, FUNCTIONFS_UNBIND);
35383539
if (!--opts->refcnt)
35393540
functionfs_unbind(ffs);
35403541

@@ -3559,7 +3560,6 @@ static void ffs_func_unbind(struct usb_configuration *c,
35593560
func->function.ssp_descriptors = NULL;
35603561
func->interfaces_nums = NULL;
35613562

3562-
ffs_event_add(ffs, FUNCTIONFS_UNBIND);
35633563
}
35643564

35653565
static struct usb_function *ffs_alloc(struct usb_function_instance *fi)

0 commit comments

Comments
 (0)