linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
To: Alan Stern <stern@rowland.harvard.edu>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Felipe Balbi <felipe.balbi@linux.intel.com>,
	Peter Chen <peter.chen@nxp.com>,
	Chunfeng Yun <chunfeng.yun@mediatek.com>,
	Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peter Senna Tschudin <peter.senna@gmail.com>,
	"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Subject: [PATCH v2 2/2] usb: misc: refactor code
Date: Mon, 3 Apr 2017 22:51:54 -0500	[thread overview]
Message-ID: <20170404035154.GA15284@embeddedgus> (raw)
In-Reply-To: <20170404034840.GA15251@embeddedgus>

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

  reply	other threads:[~2017-04-04  3:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20170221153958.Horde.6KlAXD4A9Gyww1VviVYeCDh@gator4166.hostgator.com>
2017-02-21 23:17 ` [PATCH] usb: misc: add a missing continue and refactor code Gustavo A. R. Silva
2017-02-22  1:40   ` Alan Stern
2017-02-22  2:48     ` Gustavo A. R. Silva
2017-02-22  5:26       ` Gustavo A. R. Silva
2017-04-03 14:39         ` [PATCH] usb: misc: add " Gustavo A. R. Silva
2017-04-03 17:57           ` Greg Kroah-Hartman
2017-04-03 18:38             ` Alan Stern
2017-04-03 19:00               ` Gustavo A. R. Silva
2017-04-03 19:47                 ` [PATCH 1/2] usb: misc: add missing continue in switch Gustavo A. R. Silva
2017-04-03 19:50                   ` [PATCH 2/2] usb: misc: refactor code Gustavo A. R. Silva
2017-04-03 21:06                     ` Alan Stern
2017-04-04  2:11                       ` Gustavo A. R. Silva
2017-04-04  3:48                         ` [PATCH v2 1/2] usb: misc: add missing continue in switch Gustavo A. R. Silva
2017-04-04  3:51                           ` Gustavo A. R. Silva [this message]
2017-04-04 13:44                             ` [PATCH v2 2/2] usb: misc: refactor code Alan Stern
2017-04-04  7:43                     ` [PATCH " Felipe Balbi
2017-04-04 11:12                       ` Gustavo A. R. Silva

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=20170404035154.GA15284@embeddedgus \
    --to=garsilva@embeddedor.com \
    --cc=chunfeng.yun@mediatek.com \
    --cc=felipe.balbi@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=peter.chen@nxp.com \
    --cc=peter.senna@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).