Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Chunfeng Yun and committed by
Greg Kroah-Hartman
4d537f37 2a738137

+28 -35
+16
drivers/usb/common/common.c
··· 16 16 #include <linux/usb/otg.h> 17 17 #include <linux/of_platform.h> 18 18 19 + static 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 + 26 + const 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 + } 33 + EXPORT_SYMBOL_GPL(usb_ep_type_string); 34 + 19 35 const char *usb_otg_state_string(enum usb_otg_state state) 20 36 { 21 37 static const char *const names[] = {
+2 -15
drivers/usb/core/hcd.c
··· 1878 1878 /* kick hcd */ 1879 1879 unlink1(hcd, urb, -ESHUTDOWN); 1880 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 1882 urb, usb_endpoint_num(&ep->desc), 1883 1883 is_in ? "in" : "out", 1884 - ({ char *s; 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 - })); 1884 + usb_ep_type_string(usb_endpoint_type(&ep->desc))); 1898 1885 usb_put_urb (urb); 1899 1886 1900 1887 /* list contents may have changed */
+1 -5
drivers/usb/gadget/udc/aspeed-vhub/epn.c
··· 593 593 static int ast_vhub_epn_enable(struct usb_ep* u_ep, 594 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 596 struct ast_vhub_ep *ep = to_ast_ep(u_ep); 601 597 struct ast_vhub_dev *dev; 602 598 struct ast_vhub *vhub; ··· 642 646 ep->epn.wedged = false; 643 647 644 648 EPDBG(ep, "Enabling [%s] %s num %d maxpacket=%d\n", 645 - ep->epn.is_in ? "in" : "out", ep_type_string[type], 649 + ep->epn.is_in ? "in" : "out", usb_ep_type_string(type), 646 650 usb_endpoint_num(desc), maxpacket); 647 651 648 652 /* Can we use DMA descriptor mode ? */
+1 -15
drivers/usb/gadget/udc/dummy_hcd.c
··· 617 617 _ep->name, 618 618 desc->bEndpointAddress & 0x0f, 619 619 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 620 - ({ char *val; 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; }), 620 + usb_ep_type_string(usb_endpoint_type(desc)), 635 621 max, ep->stream_en ? "enabled" : "disabled"); 636 622 637 623 /* at this point real hardware should be NAKing transfers
+8
include/linux/usb/ch9.h
··· 37 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 + */ 45 + extern const char *usb_ep_type_string(int ep_type); 46 + 47 + /** 40 48 * usb_speed_string() - Returns human readable-name of the speed. 41 49 * @speed: The speed to return human-readable name for. If it's not 42 50 * any of the speeds defined in usb_device_speed enum, string for