summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChunfeng Yun <chunfeng.yun@mediatek.com>2019-03-20 22:27:56 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-03-26 03:45:03 -0400
commit4d537f37e0d39f64687be71087dca607ee507f5a (patch)
tree9135adefda02e372d0d0286098e05ddf6d301ff0
parent2a738137b4c2dfddae03cd44f5b5f24f745c2864 (diff)
usb: introduce usb_ep_type_string() function
In some places, the code prints a human-readable USB endpoint transfer type (e.g. "bulk"). This involves a switch statement sometimes wrapped around in ({ ... }) block leading to code repetition. To make this scenario easier, here introduces usb_ep_type_string() function, which returns a human-readable name of provided endpoint type. It also changes a few places switch was used to use this new function. Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/common/common.c16
-rw-r--r--drivers/usb/core/hcd.c17
-rw-r--r--drivers/usb/gadget/udc/aspeed-vhub/epn.c6
-rw-r--r--drivers/usb/gadget/udc/dummy_hcd.c16
-rw-r--r--include/linux/usb/ch9.h8
5 files changed, 28 insertions, 35 deletions
diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index 48277bbc15e4..2174dd9ec176 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -16,6 +16,22 @@
16#include <linux/usb/otg.h> 16#include <linux/usb/otg.h>
17#include <linux/of_platform.h> 17#include <linux/of_platform.h>
18 18
19static const char *const ep_type_names[] = {
20 [USB_ENDPOINT_XFER_CONTROL] = "ctrl",
21 [USB_ENDPOINT_XFER_ISOC] = "isoc",
22 [USB_ENDPOINT_XFER_BULK] = "bulk",
23 [USB_ENDPOINT_XFER_INT] = "intr",
24};
25
26const char *usb_ep_type_string(int ep_type)
27{
28 if (ep_type < 0 || ep_type >= ARRAY_SIZE(ep_type_names))
29 return "unknown";
30
31 return ep_type_names[ep_type];
32}
33EXPORT_SYMBOL_GPL(usb_ep_type_string);
34
19const char *usb_otg_state_string(enum usb_otg_state state) 35const char *usb_otg_state_string(enum usb_otg_state state)
20{ 36{
21 static const char *const names[] = { 37 static const char *const names[] = {
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index b227a2651e7c..35f7e5fdf4da 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1878,23 +1878,10 @@ rescan:
1878 /* kick hcd */ 1878 /* kick hcd */
1879 unlink1(hcd, urb, -ESHUTDOWN); 1879 unlink1(hcd, urb, -ESHUTDOWN);
1880 dev_dbg (hcd->self.controller, 1880 dev_dbg (hcd->self.controller,
1881 "shutdown urb %pK ep%d%s%s\n", 1881 "shutdown urb %pK ep%d%s-%s\n",
1882 urb, usb_endpoint_num(&ep->desc), 1882 urb, usb_endpoint_num(&ep->desc),
1883 is_in ? "in" : "out", 1883 is_in ? "in" : "out",
1884 ({ char *s; 1884 usb_ep_type_string(usb_endpoint_type(&ep->desc)));
1885
1886 switch (usb_endpoint_type(&ep->desc)) {
1887 case USB_ENDPOINT_XFER_CONTROL:
1888 s = ""; break;
1889 case USB_ENDPOINT_XFER_BULK:
1890 s = "-bulk"; break;
1891 case USB_ENDPOINT_XFER_INT:
1892 s = "-intr"; break;
1893 default:
1894 s = "-iso"; break;
1895 };
1896 s;
1897 }));
1898 usb_put_urb (urb); 1885 usb_put_urb (urb);
1899 1886
1900 /* list contents may have changed */ 1887 /* list contents may have changed */
diff --git a/drivers/usb/gadget/udc/aspeed-vhub/epn.c b/drivers/usb/gadget/udc/aspeed-vhub/epn.c
index 83340f4fdc6e..35941dc125f9 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/epn.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/epn.c
@@ -593,10 +593,6 @@ static int ast_vhub_epn_disable(struct usb_ep* u_ep)
593static int ast_vhub_epn_enable(struct usb_ep* u_ep, 593static int ast_vhub_epn_enable(struct usb_ep* u_ep,
594 const struct usb_endpoint_descriptor *desc) 594 const struct usb_endpoint_descriptor *desc)
595{ 595{
596 static const char *ep_type_string[] __maybe_unused = { "ctrl",
597 "isoc",
598 "bulk",
599 "intr" };
600 struct ast_vhub_ep *ep = to_ast_ep(u_ep); 596 struct ast_vhub_ep *ep = to_ast_ep(u_ep);
601 struct ast_vhub_dev *dev; 597 struct ast_vhub_dev *dev;
602 struct ast_vhub *vhub; 598 struct ast_vhub *vhub;
@@ -646,7 +642,7 @@ static int ast_vhub_epn_enable(struct usb_ep* u_ep,
646 ep->epn.wedged = false; 642 ep->epn.wedged = false;
647 643
648 EPDBG(ep, "Enabling [%s] %s num %d maxpacket=%d\n", 644 EPDBG(ep, "Enabling [%s] %s num %d maxpacket=%d\n",
649 ep->epn.is_in ? "in" : "out", ep_type_string[type], 645 ep->epn.is_in ? "in" : "out", usb_ep_type_string(type),
650 usb_endpoint_num(desc), maxpacket); 646 usb_endpoint_num(desc), maxpacket);
651 647
652 /* Can we use DMA descriptor mode ? */ 648 /* Can we use DMA descriptor mode ? */
diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
index baf72f95f0f1..40c6a484e232 100644
--- a/drivers/usb/gadget/udc/dummy_hcd.c
+++ b/drivers/usb/gadget/udc/dummy_hcd.c
@@ -617,21 +617,7 @@ static int dummy_enable(struct usb_ep *_ep,
617 _ep->name, 617 _ep->name,
618 desc->bEndpointAddress & 0x0f, 618 desc->bEndpointAddress & 0x0f,
619 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 619 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
620 ({ char *val; 620 usb_ep_type_string(usb_endpoint_type(desc)),
621 switch (usb_endpoint_type(desc)) {
622 case USB_ENDPOINT_XFER_BULK:
623 val = "bulk";
624 break;
625 case USB_ENDPOINT_XFER_ISOC:
626 val = "iso";
627 break;
628 case USB_ENDPOINT_XFER_INT:
629 val = "intr";
630 break;
631 default:
632 val = "ctrl";
633 break;
634 } val; }),
635 max, ep->stream_en ? "enabled" : "disabled"); 621 max, ep->stream_en ? "enabled" : "disabled");
636 622
637 /* at this point real hardware should be NAKing transfers 623 /* at this point real hardware should be NAKing transfers
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 523aa088f6ab..da82606be605 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -37,6 +37,14 @@
37#include <uapi/linux/usb/ch9.h> 37#include <uapi/linux/usb/ch9.h>
38 38
39/** 39/**
40 * usb_ep_type_string() - Returns human readable-name of the endpoint type.
41 * @ep_type: The endpoint type to return human-readable name for. If it's not
42 * any of the types: USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT},
43 * usually got by usb_endpoint_type(), the string 'unknown' will be returned.
44 */
45extern const char *usb_ep_type_string(int ep_type);
46
47/**
40 * usb_speed_string() - Returns human readable-name of the speed. 48 * usb_speed_string() - Returns human readable-name of the speed.
41 * @speed: The speed to return human-readable name for. If it's not 49 * @speed: The speed to return human-readable name for. If it's not
42 * any of the speeds defined in usb_device_speed enum, string for 50 * any of the speeds defined in usb_device_speed enum, string for