A warning message that was recently added to the PM core has alerted
us to a potential problem in usb-storage.  Although the USB interface
is in the runtime active state when the probe routine starts, until
the runtime-PM usage count is incremented nothing forces it to remain
active.  The increment doesn't happen until after scsi_add_host() is
called, and that call causes the interface to go into runtime suspend.

Although this hasn't caused anything to go wrong for anyone, as far as
I know, it still is a bug.

To prevent this from happening, move the existing call to
usb_autopm_get_interface_no_resume() up from its current position to
before scsi_add_host() is called.

Signed-off-by: Alan Stern <st...@rowland.harvard.edu>
Reported-by: Carsten Mattner <carstenmatt...@gmail.com>
Tested-by: Carsten Mattner <carstenmatt...@gmail.com>
CC: <sta...@vger.kernel.org>



 drivers/usb/storage/usb.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Index: usb-4.x/drivers/usb/storage/usb.c
--- usb-4.x.orig/drivers/usb/storage/usb.c
+++ usb-4.x/drivers/usb/storage/usb.c
@@ -1070,17 +1070,18 @@ int usb_stor_probe2(struct us_data *us)
        result = usb_stor_acquire_resources(us);
        if (result)
                goto BadDevice;
+       usb_autopm_get_interface_no_resume(us->pusb_intf);
        snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s",
        result = scsi_add_host(us_to_host(us), dev);
        if (result) {
                                "Unable to add the scsi host\n");
-               goto BadDevice;
+               goto AddHostFailed;
        /* Submit the delayed_work for SCSI-device scanning */
-       usb_autopm_get_interface_no_resume(us->pusb_intf);
        set_bit(US_FLIDX_SCAN_PENDING, &us->dflags);
        if (delay_use > 0)
@@ -1090,7 +1091,9 @@ int usb_stor_probe2(struct us_data *us)
        return 0;
        /* We come here if there are any problems */
+ AddHostFailed:
+       usb_autopm_put_interface_no_suspend(us->pusb_intf);
+ BadDevice:
        usb_stor_dbg(us, "storage_probe() failed\n");
        return result;

To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to