From patchwork Mon Jul 11 02:54:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 71705 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp395535qga; Sun, 10 Jul 2016 19:55:55 -0700 (PDT) X-Received: by 10.66.235.227 with SMTP id up3mr31033381pac.32.1468205755667; Sun, 10 Jul 2016 19:55:55 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1si1744185pav.243.2016.07.10.19.55.55; Sun, 10 Jul 2016 19:55:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757599AbcGKCzx (ORCPT + 30 others); Sun, 10 Jul 2016 22:55:53 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:34652 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757529AbcGKCzt (ORCPT ); Sun, 10 Jul 2016 22:55:49 -0400 Received: by mail-pf0-f178.google.com with SMTP id h14so30805923pfe.1 for ; Sun, 10 Jul 2016 19:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=ARJdKf0ickAkN+pB7MnkaifzRJKSQZCs5RAz0JLwa1g=; b=Gjf4mAvQI8O0eRTfFbPbmZmD2dNsMhkosNxmD0HbX5hjjqCAuo+Xf3kD32naX/v4vP NvnggDEZtsaQ2KBgA1g5i9VLtXRJCradxmkAUfnjPKWr1fIDlPt1ta/LlBxYzLQJsP1a g/t4K5XLRjPngTcI4ENPr7gE2b/O7T5f2VyFI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ARJdKf0ickAkN+pB7MnkaifzRJKSQZCs5RAz0JLwa1g=; b=NOL/yuSYvg0VLphfbe1b1AW9bsOZhjdd5b3DJw54+FqGZc0HNnBHCbODPHQVU+Mo3t tv9Kle0h4M8uFowqTMmiOBK0M8qem8Mq+MkrQRlb8kvaEsJOulkNS+V9VNg+3O2XNOVS kJn66DvCTsMPUdEmDskladScZYPq3z16cUAfupeI9ryjzLDc7fINPncQcu/VT9vOksPg /Uu4MdoxRsDEzlDGFVA/mZK5FHQSxcpMXj0+13S0BWP922cwVUiLHkrEToQVYOglNZ+H a6ddBzJP+2XZPQq5Xiuabj4s1HysXEySjEsuRHAaQUSs/5qdvlSMqotdHnpioQ+hfDZ/ n9fw== X-Gm-Message-State: ALyK8tIGnsyKXiYM4F0t9IgPgNcskKVS7Qr5VgDOiiN87ApM7DLNreZDjhMWT7htAACmc2dA X-Received: by 10.98.24.194 with SMTP id 185mr18966000pfy.52.1468205749142; Sun, 10 Jul 2016 19:55:49 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id yt4sm166932pab.26.2016.07.10.19.55.45 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 10 Jul 2016 19:55:48 -0700 (PDT) From: Baolin Wang To: balbi@kernel.org Cc: gregkh@linuxfoundation.org, eu@felipetonello.com, mina86@mina86.com, r.baldyga@samsung.com, dan.carpenter@oracle.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, broonie@kernel.org, baolin.wang@linaro.org Subject: [PATCH v2] usb: gadget: f_midi: Add checking if it need align buffer's size to an ep's maxpacketsize Date: Mon, 11 Jul 2016 10:54:58 +0800 Message-Id: <2615165a391e3a7c2a75b094c39331bbce5ce850.1468205347.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some gadget device (such as dwc3 gadget) requires quirk_ep_out_aligned_size attribute, which means it need to align the request buffer's size to an ep's maxpacketsize. Thus we add usb_ep_align_maybe() function to check if it is need to align the request buffer's size to an ep's maxpacketsize. Signed-off-by: Baolin Wang Acked-by: Michal Nazarewicz --- Changelog since v1: - Remove the in_ep modification. - Remove max_t() function. drivers/usb/gadget/function/f_midi.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) -- 1.7.9.5 diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c index 58fc199..59f6278 100644 --- a/drivers/usb/gadget/function/f_midi.c +++ b/drivers/usb/gadget/function/f_midi.c @@ -359,10 +359,14 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) /* allocate a bunch of read buffers and queue them all at once. */ for (i = 0; i < midi->qlen && err == 0; i++) { - struct usb_request *req = - midi_alloc_ep_req(midi->out_ep, - max_t(unsigned, midi->buflen, - bulk_out_desc.wMaxPacketSize)); + struct usb_request *req; + unsigned length; + + length = midi->buflen < bulk_out_desc.wMaxPacketSize + ? bulk_out_desc.wMaxPacketSize + : usb_ep_align_maybe(midi->gadget, midi->out_ep, + midi->buflen); + req = midi_alloc_ep_req(midi->out_ep, length); if (req == NULL) return -ENOMEM;