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


Groups > linux.kernel > #1615523 > unrolled thread

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

Started by"Gustavo A. R. Silva" <garsilva@embeddedor.com>
First post2017-04-03 22:00 +0200
Last post2017-04-04 13:20 +0200
Articles 8 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [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

#1615523 — [PATCH 2/2] usb: misc: refactor code

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-04-03 22:00 +0200
Subject[PATCH 2/2] usb: misc: refactor code
Message-ID<tsgiS-2PU-13@gated-at.bofh.it>
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;
 
 	for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
-		unsigned	ep;
+		unsigned        ep;
 
 		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;
+			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 */
 			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;
-- 
2.5.0

[toc] | [next] | [standalone]


#1615557

FromAlan Stern <stern@rowland.harvard.edu>
Date2017-04-03 23:10 +0200
Message-ID<tshoD-3Mv-33@gated-at.bofh.it>
In reply to#1615523
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;
> 

[toc] | [prev] | [next] | [standalone]


#1615665

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-04-04 04:40 +0200
Message-ID<tsmxY-76q-9@gated-at.bofh.it>
In reply to#1615557
Hi Alan,

Quoting Alan Stern <stern@rowland.harvard.edu>:

> 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?
>

Yeah, well, certainly none at all. This is what happened: I created a  
local copy of my changes(this piece of code included) and fixed some  
issues in a previous patch, then I did a git revert and moved my  
changes back to the original file. During this process the tabs were  
replaced with spaces in the original file, then I had to add the tabs  
again and this was the resulting patch.

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

Same as above.

>>
>>  		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?
>

Same as above.

>> +			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?
>

Oh, I based this change in the following comment to another patch I  
sent some weeks ago:
https://lkml.org/lkml/2017/2/10/293

It is due to Coding Style.

> 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;
>>

Thanks for your comments.
--
Gustavo A. R. Silva

[toc] | [prev] | [next] | [standalone]


#1615689 — [PATCH v2 1/2] usb: misc: add missing continue in switch

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-04-04 05:50 +0200
Subject[PATCH v2 1/2] usb: misc: add missing continue in switch
Message-ID<tsnDH-7L4-3@gated-at.bofh.it>
In reply to#1615665
Add missing continue in switch.

Addresses-Coverity-ID: 1248733
Cc: Alan Stern <stern@rowloand.harvard.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
Changes in v2:
 None.

 drivers/usb/misc/usbtest.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 3525626..7bfb6b78 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -159,6 +159,7 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
 			case USB_ENDPOINT_XFER_INT:
 				if (dev->info->intr)
 					goto try_intr;
+				continue;
 			case USB_ENDPOINT_XFER_ISOC:
 				if (dev->info->iso)
 					goto try_iso;
-- 
2.5.0

[toc] | [prev] | [next] | [standalone]


#1615693 — [PATCH v2 2/2] usb: misc: refactor code

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-04-04 06:00 +0200
Subject[PATCH v2 2/2] usb: misc: refactor code
Message-ID<tsnNn-7On-1@gated-at.bofh.it>
In reply to#1615689
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>
---
Changes in v2:
 Remove unfruitful changes in previous patch.
 Revert change to comment.

 drivers/usb/misc/usbtest.c | 49 ++++++++++++++++++++--------------------------
 1 file changed, 21 insertions(+), 28 deletions(-)

diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 7bfb6b78..88f627e 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -124,6 +124,20 @@ 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)
 {
@@ -151,47 +165,26 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
 		 */
 		for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
 			struct usb_host_endpoint	*e;
+			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;
+					endpoint_update(edi, &iso_in, &iso_out, e);
 				/* FALLTHROUGH */
 			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;
-- 
2.5.0

[toc] | [prev] | [next] | [standalone]


#1616038 — Re: [PATCH v2 2/2] usb: misc: refactor code

FromAlan Stern <stern@rowland.harvard.edu>
Date2017-04-04 15:50 +0200
SubjectRe: [PATCH v2 2/2] usb: misc: refactor code
Message-ID<tsx0l-5yd-11@gated-at.bofh.it>
In reply to#1615693
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>
> ---
> Changes in v2:
>  Remove unfruitful changes in previous patch.
>  Revert change to comment.

For both patches:

Acked-by: Alan Stern <stern@rowland.harvard.edu>

>  drivers/usb/misc/usbtest.c | 49 ++++++++++++++++++++--------------------------
>  1 file changed, 21 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
> index 7bfb6b78..88f627e 100644
> --- a/drivers/usb/misc/usbtest.c
> +++ b/drivers/usb/misc/usbtest.c
> @@ -124,6 +124,20 @@ 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)
>  {
> @@ -151,47 +165,26 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
>  		 */
>  		for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
>  			struct usb_host_endpoint	*e;
> +			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;
> +					endpoint_update(edi, &iso_in, &iso_out, e);
>  				/* FALLTHROUGH */
>  			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;
> 

[toc] | [prev] | [next] | [standalone]


#1615759

FromFelipe Balbi <felipe.balbi@linux.intel.com>
Date2017-04-04 09:50 +0200
Message-ID<tsrnX-1QN-13@gated-at.bofh.it>
In reply to#1615523

[Multipart message — attachments visible in raw view] — view raw

Hi,

"Gustavo A. R. Silva" <garsilva@embeddedor.com> writes:
> 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;

unnecessary change

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

unnecessary change

>  
>  		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;

unnecessary change

-- 
balbi

[toc] | [prev] | [next] | [standalone]


#1615919

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-04-04 13:20 +0200
Message-ID<tsuFc-478-13@gated-at.bofh.it>
In reply to#1615759
Hello,

Quoting Felipe Balbi <felipe.balbi@linux.intel.com>:

> Hi,
>
> "Gustavo A. R. Silva" <garsilva@embeddedor.com> writes:
>> 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;
>
> unnecessary change
>
>>
>>  	for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
>> -		unsigned	ep;
>> +		unsigned        ep;
>
> unnecessary change
>
>>
>>  		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;
>
> unnecessary change
>

I already sent the version 2 of this patch: https://lkml.org/lkml/2017/4/3/856

Thanks
--
Gustavo A. R. Silva

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web