From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
Alan Stern <stern@rowland.harvard.edu>,
Matthew Dharm <mdharm-usb@one-eyed-alien.net>
Subject: [58/89] usb-storage: redo incorrect reads
Date: Wed, 15 Jun 2011 17:00:21 -0700 [thread overview]
Message-ID: <20110616000234.690426706@clark.kroah.org> (raw)
In-Reply-To: <20110616000258.GA14529@kroah.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 7197 bytes --]
2.6.39-stable review patch. If anyone has any objections, please let us know.
------------------
From: Alan Stern <stern@rowland.harvard.edu>
commit 21c13a4f7bc185552c4b402b792c3bbb9aa69df0 upstream.
Some USB mass-storage devices have bugs that cause them not to handle
the first READ(10) command they receive correctly. The Corsair
Padlock v2 returns completely bogus data for its first read (possibly
it returns the data in encrypted form even though the device is
supposed to be unlocked). The Feiya SD/SDHC card reader fails to
complete the first READ(10) command after it is plugged in or after a
new card is inserted, returning a status code that indicates it thinks
the command was invalid, which prevents the kernel from retrying the
read.
Since the first read of a new device or a new medium is for the
partition sector, the kernel is unable to retrieve the device's
partition table. Users have to manually issue an "hdparm -z" or
"blockdev --rereadpt" command before they can access the device.
This patch (as1470) works around the problem. It adds a new quirk
flag, US_FL_INVALID_READ10, indicating that the first READ(10) should
always be retried immediately, as should any failing READ(10) commands
(provided the preceding READ(10) command succeeded, to avoid getting
stuck in a loop). The patch also adds appropriate unusual_devs
entries containing the new flag.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Tested-by: Sven Geggus <sven-usbst@geggus.net>
Tested-by: Paul Hartman <paul.hartman+linux@gmail.com>
CC: Matthew Dharm <mdharm-usb@one-eyed-alien.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
Documentation/kernel-parameters.txt | 2 ++
drivers/usb/storage/transport.c | 29 +++++++++++++++++++++++++++++
drivers/usb/storage/unusual_devs.h | 19 +++++++++++++++++++
drivers/usb/storage/usb.c | 13 ++++++++++++-
drivers/usb/storage/usb.h | 2 ++
include/linux/usb_usual.h | 4 +++-
6 files changed, 67 insertions(+), 2 deletions(-)
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -2590,6 +2590,8 @@ bytes respectively. Such letter suffixes
unlock ejectable media);
m = MAX_SECTORS_64 (don't transfer more
than 64 sectors = 32 KB at a time);
+ n = INITIAL_READ10 (force a retry of the
+ initial READ(10) command);
o = CAPACITY_OK (accept the capacity
reported by the device);
r = IGNORE_RESIDUE (the device reports
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -819,6 +819,35 @@ Retry_Sense:
}
}
+ /*
+ * Some devices don't work or return incorrect data the first
+ * time they get a READ(10) command, or for the first READ(10)
+ * after a media change. If the INITIAL_READ10 flag is set,
+ * keep track of whether READ(10) commands succeed. If the
+ * previous one succeeded and this one failed, set the REDO_READ10
+ * flag to force a retry.
+ */
+ if (unlikely((us->fflags & US_FL_INITIAL_READ10) &&
+ srb->cmnd[0] == READ_10)) {
+ if (srb->result == SAM_STAT_GOOD) {
+ set_bit(US_FLIDX_READ10_WORKED, &us->dflags);
+ } else if (test_bit(US_FLIDX_READ10_WORKED, &us->dflags)) {
+ clear_bit(US_FLIDX_READ10_WORKED, &us->dflags);
+ set_bit(US_FLIDX_REDO_READ10, &us->dflags);
+ }
+
+ /*
+ * Next, if the REDO_READ10 flag is set, return a result
+ * code that will cause the SCSI core to retry the READ(10)
+ * command immediately.
+ */
+ if (test_bit(US_FLIDX_REDO_READ10, &us->dflags)) {
+ clear_bit(US_FLIDX_REDO_READ10, &us->dflags);
+ srb->result = DID_IMM_RETRY << 16;
+ srb->sense_buffer[0] = 0;
+ }
+ }
+
/* Did we transfer less than the minimum amount required? */
if ((srb->result == SAM_STAT_GOOD || srb->sense_buffer[2] == 0) &&
scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow)
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -1114,6 +1114,16 @@ UNUSUAL_DEV( 0x090c, 0x1132, 0x0000, 0xf
USB_SC_DEVICE, USB_PR_DEVICE, NULL,
US_FL_FIX_CAPACITY ),
+/* Reported by Paul Hartman <paul.hartman+linux@gmail.com>
+ * This card reader returns "Illegal Request, Logical Block Address
+ * Out of Range" for the first READ(10) after a new card is inserted.
+ */
+UNUSUAL_DEV( 0x090c, 0x6000, 0x0100, 0x0100,
+ "Feiya",
+ "SD/SDHC Card Reader",
+ USB_SC_DEVICE, USB_PR_DEVICE, NULL,
+ US_FL_INITIAL_READ10 ),
+
/* This Pentax still camera is not conformant
* to the USB storage specification: -
* - It does not like the INQUIRY command. So we must handle this command
@@ -1888,6 +1898,15 @@ UNUSUAL_DEV( 0x1908, 0x3335, 0x0200, 0x0
USB_SC_DEVICE, USB_PR_DEVICE, NULL,
US_FL_NO_READ_DISC_INFO ),
+/* Reported by Sven Geggus <sven-usbst@geggus.net>
+ * This encrypted pen drive returns bogus data for the initial READ(10).
+ */
+UNUSUAL_DEV( 0x1b1c, 0x1ab5, 0x0200, 0x0200,
+ "Corsair",
+ "Padlock v2",
+ USB_SC_DEVICE, USB_PR_DEVICE, NULL,
+ US_FL_INITIAL_READ10 ),
+
/* Patch by Richard Schütz <r.schtz@t-online.de>
* This external hard drive enclosure uses a JMicron chip which
* needs the US_FL_IGNORE_RESIDUE flag to work properly. */
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -439,7 +439,8 @@ static void adjust_quirks(struct us_data
US_FL_CAPACITY_HEURISTICS | US_FL_IGNORE_DEVICE |
US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 |
US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE |
- US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT);
+ US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT |
+ US_FL_INITIAL_READ10);
p = quirks;
while (*p) {
@@ -483,6 +484,9 @@ static void adjust_quirks(struct us_data
case 'm':
f |= US_FL_MAX_SECTORS_64;
break;
+ case 'n':
+ f |= US_FL_INITIAL_READ10;
+ break;
case 'o':
f |= US_FL_CAPACITY_OK;
break;
@@ -946,6 +950,13 @@ int usb_stor_probe2(struct us_data *us)
if (result)
goto BadDevice;
+ /*
+ * If the device returns invalid data for the first READ(10)
+ * command, indicate the command should be retried.
+ */
+ if (us->fflags & US_FL_INITIAL_READ10)
+ set_bit(US_FLIDX_REDO_READ10, &us->dflags);
+
/* Acquire all the other resources and add the host */
result = usb_stor_acquire_resources(us);
if (result)
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -73,6 +73,8 @@ struct us_unusual_dev {
#define US_FLIDX_RESETTING 4 /* device reset in progress */
#define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */
#define US_FLIDX_DONT_SCAN 6 /* don't scan (disconnect) */
+#define US_FLIDX_REDO_READ10 7 /* redo READ(10) command */
+#define US_FLIDX_READ10_WORKED 8 /* previous READ(10) succeeded */
#define USB_STOR_STRING_LEN 32
--- a/include/linux/usb_usual.h
+++ b/include/linux/usb_usual.h
@@ -62,7 +62,9 @@
US_FLAG(NO_READ_DISC_INFO, 0x00040000) \
/* cannot handle READ_DISC_INFO */ \
US_FLAG(NO_READ_CAPACITY_16, 0x00080000) \
- /* cannot handle READ_CAPACITY_16 */
+ /* cannot handle READ_CAPACITY_16 */ \
+ US_FLAG(INITIAL_READ10, 0x00100000) \
+ /* Initial READ(10) (and others) must be retried */
#define US_FLAG(name, value) US_FL_##name = value ,
enum { US_DO_ALL_FLAGS };
next prev parent reply other threads:[~2011-06-16 7:34 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-16 0:02 [00/89] 2.6.39.2-stable review Greg KH
2011-06-15 23:59 ` [01/89] lguest: fix timer interrupt setup Greg KH
2011-06-15 23:59 ` [02/89] intel-iommu: Flush unmaps at domain_exit Greg KH
2011-06-15 23:59 ` [03/89] intel-iommu: Only unlink device domains from iommu Greg KH
2011-06-15 23:59 ` [04/89] intel-iommu: Check for identity mapping candidate using Greg KH
2011-06-15 23:59 ` [05/89] intel-iommu: Speed up processing of the identity_mapping Greg KH
2011-06-15 23:59 ` [06/89] intel-iommu: Dont cache iova above 32bit Greg KH
2011-06-15 23:59 ` [07/89] intel-iommu: Use coherent DMA mask when requested Greg KH
2011-06-15 23:59 ` [08/89] intel-iommu: Remove Host Bridge devices from identity Greg KH
2011-06-15 23:59 ` [09/89] intel-iommu: Add domain check in domain_remove_one_dev_info Greg KH
2011-06-15 23:59 ` [10/89] powerpc/4xx: Fix regression in SMP on 476 Greg KH
2011-06-15 23:59 ` [11/89] arch/tile: allocate PCI IRQs later in boot Greg KH
2011-06-15 23:59 ` [12/89] UBIFS: fix shrinker object count reports Greg KH
2011-06-15 23:59 ` [13/89] UBIFS: fix memory leak on error path Greg KH
2011-06-15 23:59 ` [14/89] block: blkdev_get() should access ->bd_disk only after Greg KH
2011-06-15 23:59 ` [15/89] nbd: limit module parameters to a sane value Greg KH
2011-06-15 23:59 ` [16/89] [SCSI] Fix oops caused by queue refcounting failure Greg KH
2011-06-15 23:59 ` [17/89] ath9k: Reset chip on baseband hang Greg KH
2011-06-15 23:59 ` [18/89] ath9k: set 40 Mhz rate only if hw is configured in ht40 Greg KH
2011-06-15 23:59 ` [19/89] ath9k: fix two more bugs in tx power Greg KH
2011-06-15 23:59 ` [20/89] hwmon: (coretemp) Fix TjMax detection for older CPUs Greg KH
2011-06-15 23:59 ` [21/89] hwmon: (coretemp) Relax target temperature range check Greg KH
2011-06-15 23:59 ` [22/89] iwl4965: fix 5GHz operation Greg KH
2011-06-15 23:59 ` [23/89] iwl4965: correctly validate temperature value Greg KH
2011-06-15 23:59 ` [24/89] zd1211rw: fix to work on OHCI Greg KH
2011-06-15 23:59 ` [25/89] mm: fix ENOSPC returned by handle_mm_fault() Greg KH
2011-06-15 23:59 ` [26/89] serial: core, move termios handling to uart_startup Greg KH
2011-06-15 23:59 ` [27/89] serial: core, do not set DTR/RTS twice on startup Greg KH
2011-06-15 23:59 ` [28/89] serial: core, remove uart_update_termios Greg KH
2011-06-15 23:59 ` [29/89] PCI: Set PCIE maxpayload for card during hotplug insertion Greg KH
2011-06-15 23:59 ` [30/89] powerpc: Fix 32-bit SMP build Greg KH
2011-06-15 23:59 ` [31/89] asus-wmi: Remove __init from asus_wmi_platform_init Greg KH
2011-06-15 23:59 ` [32/89] nl80211: fix check for valid SSID size in scan operations Greg KH
2011-06-15 23:59 ` [33/89] block: export blk_{get,put}_queue() Greg KH
2011-06-15 23:59 ` [34/89] usbnet/cdc_ncm: add missing .reset_resume hook Greg KH
2011-06-15 23:59 ` [35/89] lockdep: Fix lock_is_held() on recursion Greg KH
2011-06-15 23:59 ` [36/89] drm/i915: Add a no lvds quirk for the Asus EeeBox PC EB1007 Greg KH
2011-06-16 0:00 ` [37/89] drm/radeon/kms: viewport height has to be even Greg KH
2011-06-16 0:00 ` [38/89] drm/radeon/kms: fix for radeon on systems >4GB without Greg KH
2011-06-16 0:00 ` [39/89] fat: Fix corrupt inode flags when remove ATTR_SYS flag Greg KH
2011-06-16 0:00 ` [40/89] xen: off by one errors in multicalls.c Greg KH
2011-06-16 0:00 ` [51/89] option: add Zoom 4597 modem USB IDs Greg KH
2011-06-16 0:00 ` [52/89] option: add Alcatel X200 to sendsetup blacklist Greg KH
2011-06-16 0:00 ` [53/89] option: add Prolink PH300 modem IDs Greg KH
2011-06-16 0:00 ` [54/89] USB: option Add blacklist for ZTE K3765-Z (19d2:2002) Greg KH
2011-06-16 0:00 ` [55/89] Revert "USB: option: add ID for ZTE MF 330" Greg KH
2011-06-16 0:00 ` [56/89] USB: core: Tolerate protocol stall during hub and port Greg KH
2011-06-16 0:00 ` [57/89] USB: serial: add another 4N-GALAXY.DE PID to ftdi_sio driver Greg KH
2011-06-16 0:00 ` Greg KH [this message]
2011-06-16 0:00 ` [59/89] Revert "x86, efi: Retain boot service code until after switching to virtual mode" Greg KH
2011-06-16 0:00 ` [60/89] xhci: Add defines for hardcoded slot states Greg KH
2011-06-16 0:00 ` [61/89] xhci: Do not issue device reset when device is not setup Greg KH
2011-06-16 0:00 ` [62/89] xhci: Disable MSI for some Fresco Logic hosts Greg KH
2011-06-16 0:00 ` [63/89] USB: xhci - fix interval calculation for FS isoc endpoints Greg KH
2011-06-16 0:00 ` [64/89] AppArmor: Fix sleep in invalid context from task_setrlimit Greg KH
2011-06-16 0:00 ` [65/89] cifs: dont allow cifs_reconnect to exit with NULL socket Greg KH
2011-06-16 0:00 ` [66/89] ASoC: AD1836: Fix setting the PCM format Greg KH
2011-06-16 0:00 ` [67/89] ASoC: Fix WM8962 headphone volume update for use of advanced Greg KH
2011-06-16 0:00 ` [68/89] ASoC: WM8804 does not support sample rates below 32kHz Greg KH
2011-06-16 0:00 ` [69/89] ASoC: snd_soc_new_{mixer,mux,pga} make sure to use right Greg KH
2011-06-16 0:00 ` [70/89] ASoC: SAMSUNG: Fix the incorrect referencing of I2SCON Greg KH
2011-06-16 0:00 ` [71/89] ALSA: hda: Fix quirk for Dell Inspiron 910 Greg KH
2011-06-16 0:00 ` [72/89] oprofile: Free potentially owned tasks in case of errors Greg KH
2011-06-16 0:00 ` [73/89] oprofile: Fix locking dependency in sync_start() Greg KH
2011-06-16 0:00 ` [74/89] oprofile, dcookies: Fix possible circular locking dependency Greg KH
2011-06-16 0:00 ` [75/89] drm/radeon/kms: do bounds checking for 3D_LOAD_VBPNTR and Greg KH
2011-06-16 0:00 ` [76/89] iwlagn: use cts-to-self protection on 5000 adapters series Greg KH
2011-06-16 0:00 ` [77/89] iwl4965: set tx power after rxon_assoc Greg KH
2011-06-16 0:00 ` [78/89] igb: fix i350 SR-IOV failture Greg KH
2011-06-16 0:00 ` [79/89] mac80211: fix IBSS teardown race Greg KH
2011-06-16 0:00 ` [80/89] x86: devicetree: Add missing early_init_dt_setup_initrd_arch Greg KH
2011-06-16 0:00 ` [81/89] x86: cpu-hotplug: Prevent softirq wakeup on wrong CPU Greg KH
2011-06-16 0:00 ` [82/89] CPUFREQ: Remove cpufreq_stats sysfs entries on module unload Greg KH
2011-06-16 0:00 ` [83/89] TOMOYO: Fix oops in tomoyo_mount_acl() Greg KH
2011-06-16 0:00 ` [84/89] md: check ->hot_remove_disk when removing disk Greg KH
2011-06-16 0:00 ` [85/89] md/raid5: fix raid5_set_bi_hw_segments Greg KH
2011-06-16 0:00 ` [86/89] md/raid5: fix FUA request handling in ops_run_io() Greg KH
2011-06-16 0:00 ` [87/89] iwlagn: send tx power command if defer cause by RXON not Greg KH
2011-06-16 0:00 ` [88/89] iwlagn: fix channel switch locking Greg KH
2011-06-16 0:00 ` [89/89] iwlegacy: " Greg KH
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=20110616000234.690426706@clark.kroah.org \
--to=gregkh@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=mdharm-usb@one-eyed-alien.net \
--cc=stable-review@kernel.org \
--cc=stable@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=torvalds@linux-foundation.org \
/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
all inboxes | Powered by JetHome®