public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Charles Hannum <root@ihack.net>
Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman <gregkh@suse.de>,
	Alan Stern <stern@rowland.harvard.edu>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	linux-usb@vger.kernel.org
Subject: Re: [PATCH] scsi/sd: fix suspend with USB-connected Android phone (one line)
Date: Thu, 12 May 2011 22:03:13 +0200	[thread overview]
Message-ID: <201105122203.13671.rjw@sisk.pl> (raw)
In-Reply-To: <BANLkTi=XNyR8GD43GGnMag+=JmhUd_5HtA@mail.gmail.com>

Hi,

Added some CCs.

On Thursday, May 12, 2011, Charles Hannum wrote:
> Short version: My laptop doesn't suspend when my Android phone is
> connected and has been “ejected”.
> 
> Long version:
> 
> Android phones connect as USB mass storage devices.  After the “Turn
> on USB storage” button has been clicked, there are a few different
> ways to detach the “disk”:
> 
> 1) pull the cable
> 2) click “Turn off USB storage”
> 3) “eject” the device
> 
> In cases 2 & 3, the USB device is still attached to the system, but
> will now return MEDIUM NOT PRESENT for many commands, including
> SYNCHRONIZE CACHE—basically it acts like any device with removable
> media.  However, the act of the “media” being removed does not
> invalidate sdkp->WCE; therefore sd_shutdown() and sd_suspend() still
> call sd_sync_cache(), which *fails* because it gets a MEDIUM NOT
> PRESENT sense code.  In the sd_suspend() case, this causes the entire
> suspend to fail, and the laptop rewakes immediately.
> 
> There are a few different ways to fix this; e.g. one could
> specifically test media_not_present() if a sense code is returned in
> sd_sync_cache().  However, the following patch seems simpler, and
> avoids calling sd_sync_cache() at all in this case.  sdkp->WCE will be
> reset when new medium is recognized and sd_read_cache_type() is
> called.  Note this code always gets called—it's in the same path as
> sd_read_capacity(), which has to be called for the device to be usable
> again; thus the patch is inherently safe.
> 
> Kernel tested: 2.6.38 (Ubuntu Natty)

Patch appended for completness.

I need someone from USB/SCSI camp to see if this approach makes sense.

Thanks,
Rafael


--- linux-2.6.38/drivers/scsi/sd.c.orig	2011-05-11 18:08:44.969497976 -0400
+++ linux-2.6.38/drivers/scsi/sd.c	2011-05-11 15:26:15.439610760 -0400
@@ -996,6 +996,7 @@
 	if (sdkp->device->removable) {
 		sdkp->media_present = 0;
 		sdkp->capacity = 0;
+		sdkp->WCE = 0;
 	}
 }
 

       reply	other threads:[~2011-05-12 20:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <BANLkTi=XNyR8GD43GGnMag+=JmhUd_5HtA@mail.gmail.com>
2011-05-12 20:03 ` Rafael J. Wysocki [this message]
2011-05-12 20:36   ` [PATCH] scsi/sd: fix suspend with USB-connected Android phone (one line) James Bottomley
     [not found]     ` <1305232563.2575.85.camel-0iu6Cu4xQGLYCGPCin2YbQ@public.gmane.org>
2011-05-12 20:59       ` Charles Hannum
2011-05-12 21:32     ` Alan Stern
2011-05-12 21:43       ` James Bottomley
2011-05-12 22:41         ` Charles Hannum
2011-05-14 19:11     ` Oliver Neukum
2011-05-16  5:56       ` Hannes Reinecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201105122203.13671.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=root@ihack.net \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox