Skip to content

Commit 8eb3e68

Browse files
groeckgregkh
authored andcommitted
usb: dwc2: Do not update data length if it is 0 on inbound transfers
[ Upstream commit 415fa1c ] The DWC2 documentation states that transfers with zero data length should set the number of packets to 1 and the transfer length to 0. This is not currently the case for inbound transfers: the transfer length is set to the maximum packet length. This can have adverse effects if the chip actually does transfer data as it is programmed to do. Follow chip documentation and keep the transfer length set to 0 in that situation. Fixes: 56f5b1c ("staging: Core files for the DWC2 driver") Tested-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de> Reviewed-by: Douglas Anderson <dianders@chromium.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de> Link: https://lore.kernel.org/r/20210113112052.17063-2-nsaenzjulienne@suse.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent cdbe8c0 commit 8eb3e68

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

drivers/usb/dwc2/hcd.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,19 +1313,20 @@ static void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
13131313
if (num_packets > max_hc_pkt_count) {
13141314
num_packets = max_hc_pkt_count;
13151315
chan->xfer_len = num_packets * chan->max_packet;
1316+
} else if (chan->ep_is_in) {
1317+
/*
1318+
* Always program an integral # of max packets
1319+
* for IN transfers.
1320+
* Note: This assumes that the input buffer is
1321+
* aligned and sized accordingly.
1322+
*/
1323+
chan->xfer_len = num_packets * chan->max_packet;
13161324
}
13171325
} else {
13181326
/* Need 1 packet for transfer length of 0 */
13191327
num_packets = 1;
13201328
}
13211329

1322-
if (chan->ep_is_in)
1323-
/*
1324-
* Always program an integral # of max packets for IN
1325-
* transfers
1326-
*/
1327-
chan->xfer_len = num_packets * chan->max_packet;
1328-
13291330
if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
13301331
chan->ep_type == USB_ENDPOINT_XFER_ISOC)
13311332
/*

0 commit comments

Comments
 (0)