Skip to content

Commit

Permalink
usb: storage: Replace mdelay with msleep in init_freecom
Browse files Browse the repository at this point in the history
init_freecom() is never called in atomic context.

init_freecom() is set as ".initFunction" through UNUSUAL_DEV().
And ->initFunction() is only called by usb_stor_acquire_resources(),
which is only called by usb_stor_probe2().
usb_stor_probe2() is called by *_probe() functions (like alauda_probe())
for each USB driver.
*_probe() functions are set ".probe" in struct usb_driver.
These functions are not called in atomic context.

Despite never getting called from atomic context, init_freecom()
calls mdelay() to busily wait.
This is not necessary and can be replaced with msleep() to
avoid busy waiting.

This is found by a static analysis tool named DCNS written by myself.
And I also manually check it.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jia-Ju Bai authored and Greg Kroah-Hartman committed Apr 22, 2018
1 parent a47060c commit 2a3dae1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/usb/storage/freecom.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,15 @@ static int init_freecom(struct us_data *us)
usb_stor_dbg(us, "result from activate reset is %d\n", result);

/* wait 250ms */
mdelay(250);
msleep(250);

/* clear reset */
result = usb_stor_control_msg(us, us->send_ctrl_pipe,
0x4d, 0x40, 0x24f8, 0x0, NULL, 0x0, 3*HZ);
usb_stor_dbg(us, "result from clear reset is %d\n", result);

/* wait 3 seconds */
mdelay(3 * 1000);
msleep(3 * 1000);

return USB_STOR_TRANSPORT_GOOD;
}
Expand Down

0 comments on commit 2a3dae1

Please sign in to comment.