Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp274795pxb; Wed, 13 Jan 2021 03:24:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJydFbS91YCeWkp95rrBzIFSeqTCDwM54ikpFxCHyXUlg32tBrZfMNeOxYHwWCOH/0rOWTCd X-Received: by 2002:a17:907:1047:: with SMTP id oy7mr1244781ejb.134.1610537044032; Wed, 13 Jan 2021 03:24:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610537044; cv=none; d=google.com; s=arc-20160816; b=LYnMQTIr7osyxshyeaZjFTnnmtQF3tV3kzejRHnSxvoXj7d+NJh9dlG4DLFjBXZnGU cteVxl57Sn5gBxAVvtOuHoxuCKK01BqSypCvnwLnrILIJUelNRTcrpn4vZosxOixzktj o8pmTJCmrb8AjBF0nBcKt5F4jTwOzpImMSZUhGn/WfAGl2S7DiKogXVkla3GI2xSHQtK 7m4WUO5t0RJlAVs4EqhXmrW64A+MbcH+tTZ3vXeCJRGXaNeJJMTeZrWlkao06kQWjfx8 21OzAW4gJll8x6nAAED6jiMwDLoduzziCTaEazv4VvO7aJDinY9J0f6zjh/qshSgsdYq 9SKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=FOLEhdBYVV74xhi1SmjYcW/sdR7+ZczQFzKrK6xT1wM=; b=oV8jo88Va9vICBZymIKNcsPX/F4LY7KOohOoYsnGSHCtNdOwRi87I/aJMU46JF/S1l AhAtrQ+I6I4EWLSgUadfYMdt5dEO4Wst/g9IL2WjBwN5Iu64Ne1kzZo/vYMUK0Eo6+nk WOP966t0ekEMTc9wJqUO7GbZJu0otPZvnWKkmCeY+gLanLwBiILlGYyME+O9kc9/+2hj /3J31h0f/0R2Fxt8C3V0JHEmLMnhyt+zTzsa4RMwwA9im7X/YuPm6AblcgyRVT6did3R qcEAzV8a0pIXSTg15f1WyUelN0DlGzQc9DiRj65mh1lys/4RTAWpdQ9P4+91Iav7tRZG mLUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d21si747598eja.412.2021.01.13.03.23.39; Wed, 13 Jan 2021 03:24:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727128AbhAMLWC (ORCPT + 99 others); Wed, 13 Jan 2021 06:22:02 -0500 Received: from mx2.suse.de ([195.135.220.15]:40996 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728179AbhAMLVq (ORCPT ); Wed, 13 Jan 2021 06:21:46 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CA0A7AF16; Wed, 13 Jan 2021 11:21:04 +0000 (UTC) From: Nicolas Saenz Julienne To: Paul Zimmerman , Felipe Balbi , Greg Kroah-Hartman , Nick Hudson , linux-usb@vger.kernel.org, Minas Harutyunyan Cc: linux@roeck-us.net, dianders@chromium.org, Nicolas Saenz Julienne , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] usb: dwc2: Do not update data length if it is 0 on inbound transfers Date: Wed, 13 Jan 2021 12:20:49 +0100 Message-Id: <20210113112052.17063-2-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113112052.17063-1-nsaenzjulienne@suse.de> References: <20210113112052.17063-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guenter Roeck 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. Signed-off-by: Guenter Roeck Reviewed-by: Douglas Anderson Fixes: 56f5b1cff22a1 ("staging: Core files for the DWC2 driver") Signed-off-by: Nicolas Saenz Julienne Tested-by: Nicolas Saenz Julienne --- drivers/usb/dwc2/hcd.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index e9ac215b9663..fc3269f5faf1 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -1313,19 +1313,20 @@ static void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg, if (num_packets > max_hc_pkt_count) { num_packets = max_hc_pkt_count; chan->xfer_len = num_packets * chan->max_packet; + } else if (chan->ep_is_in) { + /* + * Always program an integral # of max packets + * for IN transfers. + * Note: This assumes that the input buffer is + * aligned and sized accordingly. + */ + chan->xfer_len = num_packets * chan->max_packet; } } else { /* Need 1 packet for transfer length of 0 */ num_packets = 1; } - if (chan->ep_is_in) - /* - * Always program an integral # of max packets for IN - * transfers - */ - chan->xfer_len = num_packets * chan->max_packet; - if (chan->ep_type == USB_ENDPOINT_XFER_INT || chan->ep_type == USB_ENDPOINT_XFER_ISOC) /* -- 2.29.2