Re: [PATCH 02/23] usb: gadget: f_sourcesink: compute req size once

From: Peter Chen
Date: Thu Nov 05 2015 - 22:10:00 EST


On Tue, Nov 03, 2015 at 01:53:41PM +0100, Robert Baldyga wrote:
> Compute request size once before the loop instead of computing it in each
> loop iteration.
>
> Signed-off-by: Robert Baldyga <r.baldyga@xxxxxxxxxxx>
> ---
> drivers/usb/gadget/function/f_sourcesink.c | 45 +++++++++++++++---------------
> 1 file changed, 22 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
> index 1d6ec88..a8b68c6 100644
> --- a/drivers/usb/gadget/function/f_sourcesink.c
> +++ b/drivers/usb/gadget/function/f_sourcesink.c
> @@ -591,31 +591,30 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in,
> {
> struct usb_ep *ep;
> struct usb_request *req;
> - int i, size, status;
> -
> - for (i = 0; i < 8; i++) {
> - if (is_iso) {
> - switch (speed) {
> - case USB_SPEED_SUPER:
> - size = ss->isoc_maxpacket *
> - (ss->isoc_mult + 1) *
> - (ss->isoc_maxburst + 1);
> - break;
> - case USB_SPEED_HIGH:
> - size = ss->isoc_maxpacket * (ss->isoc_mult + 1);
> - break;
> - default:
> - size = ss->isoc_maxpacket > 1023 ?
> - 1023 : ss->isoc_maxpacket;
> - break;
> - }
> - ep = is_in ? ss->iso_in_ep : ss->iso_out_ep;
> - req = ss_alloc_ep_req(ep, size);
> - } else {
> - ep = is_in ? ss->in_ep : ss->out_ep;
> - req = ss_alloc_ep_req(ep, 0);
> + int i, size = 0, status;
> +
> + if (is_iso) {
> + switch (speed) {
> + case USB_SPEED_SUPER:
> + size = ss->isoc_maxpacket *
> + (ss->isoc_mult + 1) *
> + (ss->isoc_maxburst + 1);
> + break;
> + case USB_SPEED_HIGH:
> + size = ss->isoc_maxpacket * (ss->isoc_mult + 1);
> + break;
> + default:
> + size = ss->isoc_maxpacket > 1023 ?
> + 1023 : ss->isoc_maxpacket;
> + break;
> }
> + ep = is_in ? ss->iso_in_ep : ss->iso_out_ep;
> + } else {
> + ep = is_in ? ss->in_ep : ss->out_ep;
> + }
>
> + for (i = 0; i < 8; i++) {
> + req = ss_alloc_ep_req(ep, size);
> if (!req)
> return -ENOMEM;
>

Reviewed-by: Peter Chen <peter.chen@xxxxxxxxxxxxx>

--

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/