Skip to content

Commit f756cbd

Browse files
AlanSterngregkh
authored andcommitted
usb-storage: revert DMA-alignment change for Wireless USB
This patch (as1110) reverts an earlier patch meant to help with Wireless USB host controllers. These controllers can have bulk maxpacket values larger than 512, which puts unusual constraints on the sizes of scatter-gather list elements. However it turns out that the block layer does not provide the support we need to enforce these constraints; merely changing the DMA alignment mask doesn't help. Hence there's no reason to keep the original patch. The Wireless USB problem will have to be solved a different way. In addition, there is a reason to get rid of the earlier patch. By dereferencing a pointer stored in the ep_in array of struct usb_device, the current code risks an invalid memory access when it runs concurrently with device removal. The members of that array are cleared before the driver's disconnect method is called, so it should not try to use them. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 86c57ed commit f756cbd

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

drivers/usb/storage/scsiglue.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ static const char* host_info(struct Scsi_Host *host)
7171
static int slave_alloc (struct scsi_device *sdev)
7272
{
7373
struct us_data *us = host_to_us(sdev->host);
74-
struct usb_host_endpoint *bulk_in_ep;
7574

7675
/*
7776
* Set the INQUIRY transfer length to 36. We don't use any of
@@ -80,16 +79,22 @@ static int slave_alloc (struct scsi_device *sdev)
8079
*/
8180
sdev->inquiry_len = 36;
8281

83-
/* Scatter-gather buffers (all but the last) must have a length
84-
* divisible by the bulk maxpacket size. Otherwise a data packet
85-
* would end up being short, causing a premature end to the data
86-
* transfer. We'll use the maxpacket value of the bulk-IN pipe
87-
* to set the SCSI device queue's DMA alignment mask.
82+
/* USB has unusual DMA-alignment requirements: Although the
83+
* starting address of each scatter-gather element doesn't matter,
84+
* the length of each element except the last must be divisible
85+
* by the Bulk maxpacket value. There's currently no way to
86+
* express this by block-layer constraints, so we'll cop out
87+
* and simply require addresses to be aligned at 512-byte
88+
* boundaries. This is okay since most block I/O involves
89+
* hardware sectors that are multiples of 512 bytes in length,
90+
* and since host controllers up through USB 2.0 have maxpacket
91+
* values no larger than 512.
92+
*
93+
* But it doesn't suffice for Wireless USB, where Bulk maxpacket
94+
* values can be as large as 2048. To make that work properly
95+
* will require changes to the block layer.
8896
*/
89-
bulk_in_ep = us->pusb_dev->ep_in[usb_pipeendpoint(us->recv_bulk_pipe)];
90-
blk_queue_update_dma_alignment(sdev->request_queue,
91-
le16_to_cpu(bulk_in_ep->desc.wMaxPacketSize) - 1);
92-
/* wMaxPacketSize must be a power of 2 */
97+
blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));
9398

9499
/*
95100
* The UFI spec treates the Peripheral Qualifier bits in an

0 commit comments

Comments
 (0)