Skip to content

Commit 549c41e

Browse files
Felipe Balbigregkh
authored andcommitted
usb: gadget: workaround storage command size issues
Try to workaround issues with bad SCSI implementations by ignoring the command size error. Signed-off-by: Felipe Balbi <[email protected]> Acked-by: Alan Stern <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8296345 commit 549c41e

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

drivers/usb/gadget/file_storage.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,11 +2676,24 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
26762676
/* Verify the length of the command itself */
26772677
if (cmnd_size != fsg->cmnd_size) {
26782678

2679-
/* Special case workaround: MS-Windows issues REQUEST SENSE
2680-
* with cbw->Length == 12 (it should be 6). */
2681-
if (fsg->cmnd[0] == SC_REQUEST_SENSE && fsg->cmnd_size == 12)
2679+
/* Special case workaround: There are plenty of buggy SCSI
2680+
* implementations. Many have issues with cbw->Length
2681+
* field passing a wrong command size. For those cases we
2682+
* always try to work around the problem by using the length
2683+
* sent by the host side provided it is at least as large
2684+
* as the correct command length.
2685+
* Examples of such cases would be MS-Windows, which issues
2686+
* REQUEST SENSE with cbw->Length == 12 where it should
2687+
* be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
2688+
* REQUEST SENSE with cbw->Length == 10 where it should
2689+
* be 6 as well.
2690+
*/
2691+
if (cmnd_size <= fsg->cmnd_size) {
2692+
DBG(fsg, "%s is buggy! Expected length %d "
2693+
"but we got %d\n", name,
2694+
cmnd_size, fsg->cmnd_size);
26822695
cmnd_size = fsg->cmnd_size;
2683-
else {
2696+
} else {
26842697
fsg->phase_error = 1;
26852698
return -EINVAL;
26862699
}

0 commit comments

Comments
 (0)