Skip to content

Commit

Permalink
usb_storage: don't use set_freezable_with_signal()
Browse files Browse the repository at this point in the history
The current implementation of set_freezable_with_signal() is buggy and
tricky to get right.  usb-storage is the only user and its use can be
avoided trivially.

All usb-storage wants is to be able to sleep with timeout and get
woken up if freezing() becomes true.  This can be trivially
implemented by doing interruptible wait w/ freezing() included in the
wait condition.  There's no reason to use set_freezable_with_signal().

Perform interruptible wait on freezing() instead of using
set_freezable_with_signal(), which is scheduled for removal.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Seth Forshee <seth.forshee@canonical.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Tejun Heo committed Nov 21, 2011
1 parent 839e340 commit ec01247
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions drivers/usb/storage/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,24 +831,25 @@ static int usb_stor_scan_thread(void * __us)

dev_dbg(dev, "device found\n");

set_freezable_with_signal();
set_freezable();

/*
* Wait for the timeout to expire or for a disconnect
*
* We can't freeze in this thread or we risk causing khubd to
* fail to freeze, but we can't be non-freezable either. Nor can
* khubd freeze while waiting for scanning to complete as it may
* hold the device lock, causing a hang when suspending devices.
* So we request a fake signal when freezing and use
* interruptible sleep to kick us out of our wait early when
* freezing happens.
* So instead of using wait_event_freezable(), explicitly test
* for (DONT_SCAN || freezing) in interruptible wait and proceed
* if any of DONT_SCAN, freezing or timeout has happened.
*/
if (delay_use > 0) {
dev_dbg(dev, "waiting for device to settle "
"before scanning\n");
wait_event_interruptible_timeout(us->delay_wait,
test_bit(US_FLIDX_DONT_SCAN, &us->dflags),
delay_use * HZ);
test_bit(US_FLIDX_DONT_SCAN, &us->dflags) ||
freezing(current), delay_use * HZ);
}

/* If the device is still connected, perform the scanning */
Expand Down

0 comments on commit ec01247

Please sign in to comment.