From: David Cohen <david.a.cohen@linux.intel.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: balbi@ti.com, gregkh@linuxfoundation.org,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Paul.Zimmerman@synopsys.com
Subject: Re: [PATCH v3 2/3] usb: ffs: check quirk to pad epout buf size when not aligned to maxpacketsize
Date: Mon, 04 Nov 2013 11:02:22 -0800 [thread overview]
Message-ID: <5277EF3E.1000109@linux.intel.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1310301331580.1312-100000@iolanthe.rowland.org>
Hi Alan,
Appreciate your comments. Please, see my reply.
On 10/30/2013 10:35 AM, Alan Stern wrote:
> On Wed, 30 Oct 2013, David Cohen wrote:
>
>> Check gadget.quirk_ep_out_aligned_size to decide if buffer size requires
>> to be aligned to maxpacketsize of an out endpoint. ffs_epfile_io() needs
>> to pad epout buffer to match above condition if quirk is found.
>>
>> Signed-off-by: David Cohen <david.a.cohen@linux.intel.com>
>> ---
>> drivers/usb/gadget/f_fs.c | 17 +++++++++++++++++
>> 1 file changed, 17 insertions(+)
>>
>> diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
>> index 75e4b78..b49dd55 100644
>> --- a/drivers/usb/gadget/f_fs.c
>> +++ b/drivers/usb/gadget/f_fs.c
>> @@ -755,10 +755,12 @@ static ssize_t ffs_epfile_io(struct file *file,
>> char __user *buf, size_t len, int read)
>> {
>> struct ffs_epfile *epfile = file->private_data;
>> + struct usb_gadget *gadget = epfile->ffs->gadget;
>> struct ffs_ep *ep;
>> char *data = NULL;
>> ssize_t ret;
>> int halt;
>> + size_t orig_len = len;
>>
>> goto first_try;
>> do {
>> @@ -794,6 +796,21 @@ first_try:
>> goto error;
>> }
>>
>> + /*
>> + * Controller requires buffer size to be aligned to
>> + * maxpacketsize of an out endpoint.
>> + */
>> + if (gadget->quirk_ep_out_aligned_size && read &&
>> + !IS_ALIGNED(len, ep->ep->desc->wMaxPacketSize)) {
>
> IS_ALIGNED works only when the second argument is a power of 2.
>
> Interrupt endpoints are not required to have maxpacket sizes that are
> powers of 2. Does this code ever get used for an interrupt endpoint?
That's a good point. It won't use interrupt ep on the case I am working
on, but f_fs allows it. I'll cover both cases in next patchset.
>
>> + size_t old_len = len;
>
> Why add old_len here when you added orig_len above?
See below.
>
>> + len = roundup(orig_len,
>> + (size_t)ep->ep->desc->wMaxPacketSize);
>> + if (unlikely(data) && len > old_len) {
>
> If the original value wasn't aligned, how can len fail to be > old_len?
This code is inside a loop. There is an unlikely case explained in the
end to loop again if ep got disabled or changed while acquiring mutex.
If that happens, I want to avoid to re-allocate buffer if previous size
was already enough. Since 'len' gets updated when aligning buf size, we
need to keep track of 'orig_len' to do only minimum necessary pad on
new alignment. 'old_len' is used to save previous value to decide for
new allocation or not. But maybe I should change it to something more
accurate like 'buf_size' or 'alloc_size'.
Br, David Cohen
next prev parent reply other threads:[~2013-11-04 18:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-30 17:06 [PATCH v3 0/3] add gadget quirk to adapt f_fs for DWC3 David Cohen
2013-10-30 17:06 ` [PATCH v3 1/3] usb: gadget: add quirk_ep_out_aligned_size field to struct usb_gadget David Cohen
2013-10-30 17:31 ` Alan Stern
2013-10-30 17:36 ` Felipe Balbi
2013-10-30 17:33 ` Felipe Balbi
2013-10-30 17:06 ` [PATCH v3 2/3] usb: ffs: check quirk to pad epout buf size when not aligned to maxpacketsize David Cohen
2013-10-30 17:35 ` Alan Stern
2013-11-04 19:02 ` David Cohen [this message]
2013-10-30 17:06 ` [PATCH v3 3/3] usb: dwc3: add quirk USB_GADGET_QUIRK_EP_OUT_ALIGNED_SIZE to gadget driver David Cohen
2013-10-30 17:35 ` Felipe Balbi
2013-10-31 19:58 ` David Cohen
2013-10-31 21:16 ` Felipe Balbi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5277EF3E.1000109@linux.intel.com \
--to=david.a.cohen@linux.intel.com \
--cc=Paul.Zimmerman@synopsys.com \
--cc=balbi@ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.