From patchwork Thu Jul 5 14:31:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QW50dGkgU2VwcMOkbMOk?= X-Patchwork-Id: 10509523 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CF86C603D7 for ; Thu, 5 Jul 2018 14:32:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE38628FA6 for ; Thu, 5 Jul 2018 14:32:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B21AB2915F; Thu, 5 Jul 2018 14:32:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 570F228FA6 for ; Thu, 5 Jul 2018 14:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753782AbeGEOct (ORCPT ); Thu, 5 Jul 2018 10:32:49 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:35718 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753991AbeGEOcq (ORCPT ); Thu, 5 Jul 2018 10:32:46 -0400 Received: by mail-lf0-f67.google.com with SMTP id i15-v6so7155747lfc.2 for ; Thu, 05 Jul 2018 07:32:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yaY1YDGPgpMG7hBljiJLmfvQL0CgCLtnyeHNDtIwHZw=; b=P2nbrOa3sqbBpYdd9sstMrRQ431YGcwyRhjtdcTTC0z4fN8uoxKaqXuhcBtNmr1BLa bUn56AopAWdpAkh84acwUUSLb5znRl5pFdgepiaekhdtBXobJwNgaBZFgnvdEFhsqC4F EopQd64V7T/6NRARQCqhpX5O3/CCMfMaFcOOXHYnSj2HY9nlbg1av0kNu7vcu73ct6qJ jb4Fhr8WKCpTBGBhOD7/LC3HjiNq1IVZTRH49B9c9eAIzeUy8EXTdV7favjwEgZBe0Xm rdhXr4ZfEUN3sXcfjqFHXLIKuhydrPMfqhWRk9d1qW5+Ca0c9AnlRbM6jftD+7o97Vt1 WrRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yaY1YDGPgpMG7hBljiJLmfvQL0CgCLtnyeHNDtIwHZw=; b=sJ60xO1tM/3Y8BSlxNhifLOtjSH5SUhDAeH2byciZWupWFjWxTJWacWTsx6JsyXULZ iNKWzQixx4szEIpcp7f3c1MXgCv/394hXZNXUkR/zXBoYn/Pvyy9c+L5tBrmGVda094n O/AcOkRTKypr84/nOGtAqOB2WYJl3FGWxy8JmPmwWv8az5qXauyxvgsRlEE7EhudLv6l opgfqHDynVckH3vBiJdXBhANxbpKX2tJ3dTjJ5sQPiLsnctLG8ipH7AkCYABv6TIGV1o KcbsZmvnJPDYoRJbLmiNpJYoFv+k7v+UrIoZRAea+BZjOIQL8l1/cpNBsZTfqCpQTKlm 7HTA== X-Gm-Message-State: APt69E3iudwnZMX8lcswNhWV/+3fl3OrtHtEVADzYYuCVDttWpu5NSPY ZB8/ahUQOLZKi2R2WrVp8iA= X-Google-Smtp-Source: AAOMgpc3sc+iZXXEMoRf94O0N0jvRbXR3RUgsOjo/1gqLOoZf8CXQOyieoSYn4lDF18C9StEvRXlag== X-Received: by 2002:a19:d189:: with SMTP id i131-v6mr4682244lfg.93.1530801165448; Thu, 05 Jul 2018 07:32:45 -0700 (PDT) Received: from griffin.lan (dtyqvkyyyyyyyyyyyyydt-3.rev.dnainternet.fi. [2001:14ba:801b:1400::7]) by smtp.gmail.com with ESMTPSA id z5-v6sm1426029lff.96.2018.07.05.07.32.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jul 2018 07:32:44 -0700 (PDT) From: =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= To: Minas Harutyunyan , John Youn , Felipe Balbi Cc: Grigor Tovmasyan , Vardan Mikayelyan , Douglas Anderson , William Wu , Greg Kroah-Hartman , linux-usb@vger.kernel.org, =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= Subject: [PATCH 2/2] usb: dwc2: Fix inefficient copy of unaligned buffers Date: Thu, 5 Jul 2018 17:31:54 +0300 Message-Id: <20180705143154.8734-3-a.seppala@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180705143154.8734-1-a.seppala@gmail.com> References: <20180705143154.8734-1-a.seppala@gmail.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make sure only to copy any actual data rather than the whole buffer, when releasing the temporary buffer used for unaligned non-isochronous transfers. Taken directly from commit 0efd937e27d5e ("USB: ehci-tegra: fix inefficient copy of unaligned buffers") Tested with Lantiq xRX200 (MIPS) and RPi Model B Rev 2 (ARM) Signed-off-by: Antti Seppälä Reviewed-by: Douglas Anderson --- drivers/usb/dwc2/hcd.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 2ed0ac18e053..6e2cdd7b93d4 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -2668,6 +2668,7 @@ static int dwc2_alloc_split_dma_aligned_buf(struct dwc2_hsotg *hsotg, static void dwc2_free_dma_aligned_buffer(struct urb *urb) { void *stored_xfer_buffer; + size_t length; if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER)) return; @@ -2676,9 +2677,14 @@ static void dwc2_free_dma_aligned_buffer(struct urb *urb) memcpy(&stored_xfer_buffer, urb->transfer_buffer + urb->transfer_buffer_length, sizeof(urb->transfer_buffer)); - if (usb_urb_dir_in(urb)) - memcpy(stored_xfer_buffer, urb->transfer_buffer, - urb->transfer_buffer_length); + if (usb_urb_dir_in(urb)) { + if (usb_pipeisoc(urb->pipe)) + length = urb->transfer_buffer_length; + else + length = urb->actual_length; + + memcpy(stored_xfer_buffer, urb->transfer_buffer, length); + } kfree(urb->transfer_buffer); urb->transfer_buffer = stored_xfer_buffer;