]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/usb/storage/usb.c
Freezer: make kernel threads nonfreezable by default
[net-next-2.6.git] / drivers / usb / storage / usb.c
index cf3fc91234e7962adfe8d57567fb81c80e84f210..28842d208bb031738c8b68d79a6ac8ec91196fe7 100644 (file)
@@ -191,16 +191,14 @@ static int storage_suspend(struct usb_interface *iface, pm_message_t message)
 {
        struct us_data *us = usb_get_intfdata(iface);
 
+       US_DEBUGP("%s\n", __FUNCTION__);
+
        /* Wait until no command is running */
        mutex_lock(&us->dev_mutex);
 
-       US_DEBUGP("%s\n", __FUNCTION__);
        if (us->suspend_resume_hook)
                (us->suspend_resume_hook)(us, US_SUSPEND);
 
-       /* When runtime PM is working, we'll set a flag to indicate
-        * whether we should autoresume when a SCSI request arrives. */
-
        mutex_unlock(&us->dev_mutex);
        return 0;
 }
@@ -209,13 +207,11 @@ static int storage_resume(struct usb_interface *iface)
 {
        struct us_data *us = usb_get_intfdata(iface);
 
-       mutex_lock(&us->dev_mutex);
-
        US_DEBUGP("%s\n", __FUNCTION__);
+
        if (us->suspend_resume_hook)
                (us->suspend_resume_hook)(us, US_RESUME);
 
-       mutex_unlock(&us->dev_mutex);
        return 0;
 }
 
@@ -313,8 +309,7 @@ static int usb_stor_control_thread(void * __us)
 {
        struct us_data *us = (struct us_data *)__us;
        struct Scsi_Host *host = us_to_host(us);
-
-       current->flags |= PF_NOFREEZE;
+       int autopm_rc;
 
        for(;;) {
                US_DEBUGP("*** thread sleeping.\n");
@@ -323,6 +318,9 @@ static int usb_stor_control_thread(void * __us)
                        
                US_DEBUGP("*** thread awakened.\n");
 
+               /* Autoresume the device */
+               autopm_rc = usb_autopm_get_interface(us->pusb_intf);
+
                /* lock the device pointers */
                mutex_lock(&(us->dev_mutex));
 
@@ -381,6 +379,12 @@ static int usb_stor_control_thread(void * __us)
                        us->srb->result = SAM_STAT_GOOD;
                }
 
+               /* Did the autoresume fail? */
+               else if (autopm_rc < 0) {
+                       US_DEBUGP("Could not wake device\n");
+                       us->srb->result = DID_ERROR << 16;
+               }
+
                /* we've got a command, let's do it! */
                else {
                        US_DEBUG(usb_stor_show_command(us->srb));
@@ -423,6 +427,10 @@ SkipForAbort:
 
                /* unlock the device pointers */
                mutex_unlock(&us->dev_mutex);
+
+               /* Start an autosuspend */
+               if (autopm_rc == 0)
+                       usb_autopm_put_interface(us->pusb_intf);
        } /* for (;;) */
 
        /* Wait until we are told to stop */
@@ -910,6 +918,7 @@ static int usb_stor_scan_thread(void * __us)
        printk(KERN_DEBUG
                "usb-storage: device found at %d\n", us->pusb_dev->devnum);
 
+       set_freezable();
        /* Wait for the timeout to expire or for a disconnect */
        if (delay_use > 0) {
                printk(KERN_DEBUG "usb-storage: waiting for device "
@@ -939,6 +948,7 @@ retry:
        }
 
        scsi_host_put(us_to_host(us));
+       usb_autopm_put_interface(us->pusb_intf);
        complete_and_exit(&threads_gone, 0);
 }
 
@@ -1028,6 +1038,7 @@ static int storage_probe(struct usb_interface *intf,
         * start it up. */
        scsi_host_get(us_to_host(us));
        atomic_inc(&total_threads);
+       usb_autopm_get_interface(intf); /* dropped in the scanning thread */
        wake_up_process(th);
 
        return 0;
@@ -1065,6 +1076,7 @@ static struct usb_driver usb_storage_driver = {
        .pre_reset =    storage_pre_reset,
        .post_reset =   storage_post_reset,
        .id_table =     storage_usb_ids,
+       .supports_autosuspend = 1,
 };
 
 static int __init usb_stor_init(void)