From patchwork Thu Jul 7 09:11:19 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: 71567 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp1297073qgy; Thu, 7 Jul 2016 02:12:10 -0700 (PDT) X-Received: by 10.66.65.109 with SMTP id w13mr50665919pas.142.1467882730034; Thu, 07 Jul 2016 02:12:10 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 14si3148562pfz.229.2016.07.07.02.12.09; Thu, 07 Jul 2016 02:12:10 -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 S933324AbcGGJMG (ORCPT + 30 others); Thu, 7 Jul 2016 05:12:06 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:32833 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756580AbcGGJMA (ORCPT ); Thu, 7 Jul 2016 05:12:00 -0400 Received: by mail-pf0-f180.google.com with SMTP id i123so4686789pfg.0 for ; Thu, 07 Jul 2016 02:11:59 -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=z5wYSs0x1qE1vmYYYHFKQ5bDSCjQwKOwLvk6GX+vMt8=; b=SHAP+nju39JdbBUMa0fsa9lDW1fVv/A9+IWfGN2Sx08NsCBXX1rZavFkAvEGVBNxk5 rx0SjA91ARFm8GuxFO11FaWgL39isLg+KfOd66ZJnYJefniyzEBe1ctaYDCrL3ZXToaY OvbrKBurFtwmuOzQPkSeZMIBun4pyPFmcxgL0= 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=z5wYSs0x1qE1vmYYYHFKQ5bDSCjQwKOwLvk6GX+vMt8=; b=ZqYwoUrhKj2zoyVfnYS9SBvoo4HCmASNnN9EQOjUDrM0apqjJNPYrcc1C2aXqp/Mqm GG7mWOhoY1eXpPYSoukWk4hlyTDO48/5a9+TL2GnGcRIi3wMxWbadMNoaweKAbujd9u2 MORlNWSoVx5gov1tMdPNCtPlUiZI3z177F3BNDTwf8brfBiS82zRF5+xSg+L6axuL0/s rEXfG1KQsQI5CSpKTaUIjtxlvYWkfvC9xdjFafhHZqPyW/GQXxoIp663fEvhKwPb/Q/k hOICeLk7WpwTQJTO+5MPQDnJoO+gESbWqrgB2lLXZeWZCbv3f+uf74D8mxy+gFhp08H1 GfiQ== X-Gm-Message-State: ALyK8tJu8CcxUfcM+0RRfavgWVA0df78FC9wfOE7Wd0EZEuAgh/CYzHQRoUeDnT/ksbpa0/J X-Received: by 10.98.97.193 with SMTP id v184mr3398338pfb.138.1467882719464; Thu, 07 Jul 2016 02:11:59 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id 20sm2966817pfw.92.2016.07.07.02.11.55 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Jul 2016 02:11:59 -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] usb: gadget: f_midi: Add checking if it need align buffer's size to an ep's maxpacketsize Date: Thu, 7 Jul 2016 17:11:19 +0800 Message-Id: <8ff4f814afc70cf9c00cc6718d7ae93fae94884a.1467881565.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 --- drivers/usb/gadget/function/f_midi.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 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..2e3f11e 100644 --- a/drivers/usb/gadget/function/f_midi.c +++ b/drivers/usb/gadget/function/f_midi.c @@ -328,7 +328,7 @@ static int f_midi_start_ep(struct f_midi *midi, static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) { struct f_midi *midi = func_to_midi(f); - unsigned i; + unsigned i, length; int err; /* we only set alt for MIDIStreaming interface */ @@ -345,9 +345,11 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) /* pre-allocate write usb requests to use on f_midi_transmit. */ while (kfifo_avail(&midi->in_req_fifo)) { - struct usb_request *req = - midi_alloc_ep_req(midi->in_ep, midi->buflen); + struct usb_request *req; + length = usb_ep_align_maybe(midi->gadget, midi->in_ep, + midi->buflen); + req = midi_alloc_ep_req(midi->in_ep, length); if (req == NULL) return -ENOMEM; @@ -359,10 +361,12 @@ 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; + + length = usb_ep_align_maybe(midi->gadget, midi->out_ep, + midi->buflen); + req = midi_alloc_ep_req(midi->out_ep, + max_t(unsigned, length, bulk_out_desc.wMaxPacketSize)); if (req == NULL) return -ENOMEM;