From patchwork Tue Jul 12 09:01:39 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: 71790 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp360995qga; Tue, 12 Jul 2016 02:02:51 -0700 (PDT) X-Received: by 10.66.62.226 with SMTP id b2mr1921602pas.119.1468314171141; Tue, 12 Jul 2016 02:02:51 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si3108973paa.114.2016.07.12.02.02.50; Tue, 12 Jul 2016 02:02:51 -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 S1753143AbcGLJCd (ORCPT + 30 others); Tue, 12 Jul 2016 05:02:33 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:35055 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753051AbcGLJCa (ORCPT ); Tue, 12 Jul 2016 05:02:30 -0400 Received: by mail-pa0-f44.google.com with SMTP id dx3so4725744pab.2 for ; Tue, 12 Jul 2016 02:02:30 -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=27MJUjhkCz7tkiNZig02nslWR8Y9SEE6Gq1l2GOOep0=; b=decoaeU5pfGsNhGmbZb6zKBw8BsIxoFBBsn29izgypCnJoy7sIsCutAE72iApJnmna myazJbTaZDHxlX7Nvl3bU35OKQd5z+HShGF6gkpiWxFKP7twXsX0XGP4JNMu6Nk/HX7F gcXTFNyKvBJpC1G1Ipf4qX3sg/zwMa+jfi+sc= 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=27MJUjhkCz7tkiNZig02nslWR8Y9SEE6Gq1l2GOOep0=; b=cPZpQnUk2jYp6OmvHpPB876/CkxP4Kh7E8sy2WfPp2eZOYkDImj9/qwkigmBbvWkDf bh/cOmvnHZqF/NMCR8AMA2yUf7IJHwT5+s5E7S/Yw4nsTzCvNXSGs74GXJN/sSWa/bB8 PTcxvJ3fCiR8JfJwHCR7iXqb4Llawxh4A+OnEgOI8DC6MCjZPob9bv29M3vLYHeFkeoW fPFXuobeRsnsm8xDIVAIMQSeIzgY+sMPF/Fho4OsccwE1FgCSfiLquoIW3oDJY2EZ3L6 cJc27kXkLWBPFJPlxWg/knDRcVCIt4fH8X0ivlizFaEtfco/lesw0Lev4NqN0+GLnP5J rI/A== X-Gm-Message-State: ALyK8tKr6YWnZH6D76PLydngaZUhY7oxoA6zj6DzvN5/1Mr3acQlr/eVELRVGj1hl2UGGUNP X-Received: by 10.66.139.133 with SMTP id qy5mr2039750pab.4.1468314149923; Tue, 12 Jul 2016 02:02:29 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id t1sm996085pfa.86.2016.07.12.02.02.26 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Jul 2016 02:02:29 -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 v3] usb: gadget: f_midi: Add checking if it need align buffer's size to an ep's maxpacketsize Date: Tue, 12 Jul 2016 17:01:39 +0800 Message-Id: <72ab9d95a2eee73f41c38db88bfe50ee103305e4.1468313958.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: v2: - Simplify the method to get buffer length. v1: - Remove the in_ep modification. - Remove max_t() function. drivers/usb/gadget/function/f_midi.c | 11 +++++++---- 1 file changed, 7 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..3486941 100644 --- a/drivers/usb/gadget/function/f_midi.c +++ b/drivers/usb/gadget/function/f_midi.c @@ -359,10 +359,13 @@ 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 = 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;