]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
usb: introduce usb_ep_type_string() function
authorChunfeng Yun <chunfeng.yun@mediatek.com>
Thu, 21 Mar 2019 02:27:56 +0000 (10:27 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 26 Mar 2019 07:45:03 +0000 (16:45 +0900)
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>
drivers/usb/common/common.c
drivers/usb/core/hcd.c
drivers/usb/gadget/udc/aspeed-vhub/epn.c
drivers/usb/gadget/udc/dummy_hcd.c
include/linux/usb/ch9.h

index 48277bbc15e4d155fc9c1c7315fcf57d6347b51e..2174dd9ec1769cdf8a803543d73afb5f75e1912b 100644 (file)
 #include <linux/usb/otg.h>
 #include <linux/of_platform.h>
 
+static const char *const ep_type_names[] = {
+       [USB_ENDPOINT_XFER_CONTROL] = "ctrl",
+       [USB_ENDPOINT_XFER_ISOC] = "isoc",
+       [USB_ENDPOINT_XFER_BULK] = "bulk",
+       [USB_ENDPOINT_XFER_INT] = "intr",
+};
+
+const char *usb_ep_type_string(int ep_type)
+{
+       if (ep_type < 0 || ep_type >= ARRAY_SIZE(ep_type_names))
+               return "unknown";
+
+       return ep_type_names[ep_type];
+}
+EXPORT_SYMBOL_GPL(usb_ep_type_string);
+
 const char *usb_otg_state_string(enum usb_otg_state state)
 {
        static const char *const names[] = {
index b227a2651e7c28f4023a300ef83dbbf40f962ecd..35f7e5fdf4da1ae8a0301f187c2340921335885f 100644 (file)
@@ -1878,23 +1878,10 @@ void usb_hcd_flush_endpoint(struct usb_device *udev,
                /* kick hcd */
                unlink1(hcd, urb, -ESHUTDOWN);
                dev_dbg (hcd->self.controller,
-                       "shutdown urb %pK ep%d%s%s\n",
+                       "shutdown urb %pK ep%d%s-%s\n",
                        urb, usb_endpoint_num(&ep->desc),
                        is_in ? "in" : "out",
-                       ({      char *s;
-
-                                switch (usb_endpoint_type(&ep->desc)) {
-                                case USB_ENDPOINT_XFER_CONTROL:
-                                       s = ""; break;
-                                case USB_ENDPOINT_XFER_BULK:
-                                       s = "-bulk"; break;
-                                case USB_ENDPOINT_XFER_INT:
-                                       s = "-intr"; break;
-                                default:
-                                       s = "-iso"; break;
-                               };
-                               s;
-                       }));
+                       usb_ep_type_string(usb_endpoint_type(&ep->desc)));
                usb_put_urb (urb);
 
                /* list contents may have changed */
index 83340f4fdc6e1702f70735424d5e15d75c75d87f..35941dc125f9aa9790a78efb88edd56b5c6c1425 100644 (file)
@@ -593,10 +593,6 @@ static int ast_vhub_epn_disable(struct usb_ep* u_ep)
 static int ast_vhub_epn_enable(struct usb_ep* u_ep,
                               const struct usb_endpoint_descriptor *desc)
 {
-       static const char *ep_type_string[] __maybe_unused = { "ctrl",
-                                                              "isoc",
-                                                              "bulk",
-                                                              "intr" };
        struct ast_vhub_ep *ep = to_ast_ep(u_ep);
        struct ast_vhub_dev *dev;
        struct ast_vhub *vhub;
@@ -646,7 +642,7 @@ static int ast_vhub_epn_enable(struct usb_ep* u_ep,
        ep->epn.wedged = false;
 
        EPDBG(ep, "Enabling [%s] %s num %d maxpacket=%d\n",
-             ep->epn.is_in ? "in" : "out", ep_type_string[type],
+             ep->epn.is_in ? "in" : "out", usb_ep_type_string(type),
              usb_endpoint_num(desc), maxpacket);
 
        /* Can we use DMA descriptor mode ? */
index baf72f95f0f1cb38ff443bc802a258b6f04ef899..40c6a484e232f529b5228b6f5718310ab9a32369 100644 (file)
@@ -617,21 +617,7 @@ static int dummy_enable(struct usb_ep *_ep,
                _ep->name,
                desc->bEndpointAddress & 0x0f,
                (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
-               ({ char *val;
-                switch (usb_endpoint_type(desc)) {
-                case USB_ENDPOINT_XFER_BULK:
-                        val = "bulk";
-                        break;
-                case USB_ENDPOINT_XFER_ISOC:
-                        val = "iso";
-                        break;
-                case USB_ENDPOINT_XFER_INT:
-                        val = "intr";
-                        break;
-                default:
-                        val = "ctrl";
-                        break;
-                } val; }),
+               usb_ep_type_string(usb_endpoint_type(desc)),
                max, ep->stream_en ? "enabled" : "disabled");
 
        /* at this point real hardware should be NAKing transfers
index 523aa088f6abefb559693547f598db50cab4d40e..da82606be605a7c0cdeee9f92cd9e874b336d49a 100644 (file)
 #include <linux/device.h>
 #include <uapi/linux/usb/ch9.h>
 
+/**
+ * usb_ep_type_string() - Returns human readable-name of the endpoint type.
+ * @ep_type: The endpoint type to return human-readable name for.  If it's not
+ *   any of the types: USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT},
+ *   usually got by usb_endpoint_type(), the string 'unknown' will be returned.
+ */
+extern const char *usb_ep_type_string(int ep_type);
+
 /**
  * usb_speed_string() - Returns human readable-name of the speed.
  * @speed: The speed to return human-readable name for.  If it's not