Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1615557

Re: [PATCH 2/2] usb: misc: refactor code

From Alan Stern <stern@rowland.harvard.edu>
Newsgroups linux.kernel
Subject Re: [PATCH 2/2] usb: misc: refactor code
Date 2017-04-03 23:10 +0200
Message-ID <tshoD-3Mv-33@gated-at.bofh.it> (permalink)
References <tsgiS-2PU-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, 3 Apr 2017, Gustavo A. R. Silva wrote:

> Code refactoring to make the flow easier to follow.
> 
> Cc: Alan Stern <stern@rowloand.harvard.edu>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  drivers/usb/misc/usbtest.c | 67 +++++++++++++++++++++-------------------------
>  1 file changed, 30 insertions(+), 37 deletions(-)
> 
> diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
> index 7bfb6b78..382491e 100644
> --- a/drivers/usb/misc/usbtest.c
> +++ b/drivers/usb/misc/usbtest.c
> @@ -124,18 +124,32 @@ static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test)
>  
>  /*-------------------------------------------------------------------------*/
>  
> +static inline void endpoint_update(int edi,
> +				   struct usb_host_endpoint **in,
> +				   struct usb_host_endpoint **out,
> +				   struct usb_host_endpoint *e)
> +{
> +	if (edi) {
> +		if (!*in)
> +			*in = e;
> +	} else {
> +		if (!*out)
> +			*out = e;
> +	}
> +}
> +
>  static int
>  get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
>  {
> -	int				tmp;
> -	struct usb_host_interface	*alt;
> -	struct usb_host_endpoint	*in, *out;
> -	struct usb_host_endpoint	*iso_in, *iso_out;
> -	struct usb_host_endpoint	*int_in, *int_out;
> -	struct usb_device		*udev;
> +	int                             tmp;
> +	struct usb_host_interface       *alt;
> +	struct usb_host_endpoint        *in, *out;
> +	struct usb_host_endpoint        *iso_in, *iso_out;
> +	struct usb_host_endpoint        *int_in, *int_out;
> +	struct usb_device               *udev;

What's the difference between these 6 lines you added and the 6 lines 
that were there originally?

>  	for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
> -		unsigned	ep;
> +		unsigned        ep;

And here?

>  
>  		in = out = NULL;
>  		iso_in = iso_out = NULL;
> @@ -150,48 +164,27 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
>  		 * ignore other endpoints and altsettings.
>  		 */
>  		for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
> -			struct usb_host_endpoint	*e;
> +			struct usb_host_endpoint        *e;

And here?

> +			int edi;
>  
>  			e = alt->endpoint + ep;
> +			edi = usb_endpoint_dir_in(&e->desc);
> +
>  			switch (usb_endpoint_type(&e->desc)) {
>  			case USB_ENDPOINT_XFER_BULK:
> -				break;
> +				endpoint_update(edi, &in, &out, e);
> +				continue;
>  			case USB_ENDPOINT_XFER_INT:
>  				if (dev->info->intr)
> -					goto try_intr;
> +					endpoint_update(edi, &int_in, &int_out, e);
>  				continue;
>  			case USB_ENDPOINT_XFER_ISOC:
>  				if (dev->info->iso)
> -					goto try_iso;
> -				/* FALLTHROUGH */
> +					endpoint_update(edi, &iso_in, &iso_out, e);
> +				/* fall through */

Why change the comment?

Alan Stern

>  			default:
>  				continue;
>  			}
> -			if (usb_endpoint_dir_in(&e->desc)) {
> -				if (!in)
> -					in = e;
> -			} else {
> -				if (!out)
> -					out = e;
> -			}
> -			continue;
> -try_intr:
> -			if (usb_endpoint_dir_in(&e->desc)) {
> -				if (!int_in)
> -					int_in = e;
> -			} else {
> -				if (!int_out)
> -					int_out = e;
> -			}
> -			continue;
> -try_iso:
> -			if (usb_endpoint_dir_in(&e->desc)) {
> -				if (!iso_in)
> -					iso_in = e;
> -			} else {
> -				if (!iso_out)
> -					iso_out = e;
> -			}
>  		}
>  		if ((in && out)  ||  iso_in || iso_out || int_in || int_out)
>  			goto found;
> 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 2/2] usb: misc: refactor code "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-04-03 22:00 +0200
  Re: [PATCH 2/2] usb: misc: refactor code Alan Stern <stern@rowland.harvard.edu> - 2017-04-03 23:10 +0200
    Re: [PATCH 2/2] usb: misc: refactor code "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-04-04 04:40 +0200
      [PATCH v2 1/2] usb: misc: add missing continue in switch "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-04-04 05:50 +0200
        [PATCH v2 2/2] usb: misc: refactor code "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-04-04 06:00 +0200
          Re: [PATCH v2 2/2] usb: misc: refactor code Alan Stern <stern@rowland.harvard.edu> - 2017-04-04 15:50 +0200
  Re: [PATCH 2/2] usb: misc: refactor code Felipe Balbi <felipe.balbi@linux.intel.com> - 2017-04-04 09:50 +0200
    Re: [PATCH 2/2] usb: misc: refactor code "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-04-04 13:20 +0200

csiph-web