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

usb: common: introduce usb_state_string()

this function will receive enum usb_device_state
and return a human-readable string from it or,
case an unknown value is passed as argument,
the string "UNKNOWN".

Signed-off-by: Felipe Balbi <balbi@ti.com>

+30
+21
drivers/usb/usb-common.c
··· 32 32 } 33 33 EXPORT_SYMBOL_GPL(usb_speed_string); 34 34 35 + const char *usb_state_string(enum usb_device_state state) 36 + { 37 + static const char *const names[] = { 38 + [USB_STATE_NOTATTACHED] = "not attached", 39 + [USB_STATE_ATTACHED] = "attached", 40 + [USB_STATE_POWERED] = "powered", 41 + [USB_STATE_RECONNECTING] = "reconnecting", 42 + [USB_STATE_UNAUTHENTICATED] = "unauthenticated", 43 + [USB_STATE_DEFAULT] = "default", 44 + [USB_STATE_ADDRESS] = "addresssed", 45 + [USB_STATE_CONFIGURED] = "configured", 46 + [USB_STATE_SUSPENDED] = "suspended", 47 + }; 48 + 49 + if (state < 0 || state >= ARRAY_SIZE(names)) 50 + return "UNKNOWN"; 51 + 52 + return names[state]; 53 + } 54 + EXPORT_SYMBOL_GPL(usb_state_string); 55 + 35 56 MODULE_LICENSE("GPL");
+9
include/linux/usb/ch9.h
··· 43 43 */ 44 44 extern const char *usb_speed_string(enum usb_device_speed speed); 45 45 46 + 47 + /** 48 + * usb_state_string - Returns human readable name for the state. 49 + * @state: The state to return a human-readable name for. If it's not 50 + * any of the states devices in usb_device_state_string enum, 51 + * the string UNKNOWN will be returned. 52 + */ 53 + extern const char *usb_state_string(enum usb_device_state state); 54 + 46 55 #endif /* __LINUX_USB_CH9_H */