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

usb: common: Patch simplify usb_decode_set_clear_feature function.

Patch adds usb_decode_test_mode and usb_decode_device_feature functions,
which allow to make more readable and simplify the
usb_decode_set_clear_feature function.

Signed-off-by: Pawel Laszczak <pawell@cadence.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>

authored by

Pawel Laszczak and committed by
Felipe Balbi
010665b4 91f255a2

+43 -46
+43 -46
drivers/usb/common/debug.c
··· 30 30 } 31 31 } 32 32 33 - static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, 34 - __u16 wValue, __u16 wIndex, 35 - char *str, size_t size) 33 + static const char *usb_decode_device_feature(u16 wValue) 34 + { 35 + switch (wValue) { 36 + case USB_DEVICE_SELF_POWERED: 37 + return "Self Powered"; 38 + case USB_DEVICE_REMOTE_WAKEUP: 39 + return "Remote Wakeup"; 40 + case USB_DEVICE_TEST_MODE: 41 + return "Test Mode"; 42 + case USB_DEVICE_U1_ENABLE: 43 + return "U1 Enable"; 44 + case USB_DEVICE_U2_ENABLE: 45 + return "U2 Enable"; 46 + case USB_DEVICE_LTM_ENABLE: 47 + return "LTM Enable"; 48 + default: 49 + return "UNKNOWN"; 50 + } 51 + } 52 + 53 + static const char *usb_decode_test_mode(u16 wIndex) 54 + { 55 + switch (wIndex) { 56 + case TEST_J: 57 + return ": TEST_J"; 58 + case TEST_K: 59 + return ": TEST_K"; 60 + case TEST_SE0_NAK: 61 + return ": TEST_SE0_NAK"; 62 + case TEST_PACKET: 63 + return ": TEST_PACKET"; 64 + case TEST_FORCE_EN: 65 + return ": TEST_FORCE_EN"; 66 + default: 67 + return ": UNKNOWN"; 68 + } 69 + } 70 + 71 + static void usb_decode_set_clear_feature(__u8 bRequestType, 72 + __u8 bRequest, __u16 wValue, 73 + __u16 wIndex, char *str, size_t size) 36 74 { 37 75 switch (bRequestType & USB_RECIP_MASK) { 38 76 case USB_RECIP_DEVICE: 39 77 snprintf(str, size, "%s Device Feature(%s%s)", 40 78 bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", 41 - ({char *s; 42 - switch (wValue) { 43 - case USB_DEVICE_SELF_POWERED: 44 - s = "Self Powered"; 45 - break; 46 - case USB_DEVICE_REMOTE_WAKEUP: 47 - s = "Remote Wakeup"; 48 - break; 49 - case USB_DEVICE_TEST_MODE: 50 - s = "Test Mode"; 51 - break; 52 - case USB_DEVICE_U1_ENABLE: 53 - s = "U1 Enable"; 54 - break; 55 - case USB_DEVICE_U2_ENABLE: 56 - s = "U2 Enable"; 57 - break; 58 - case USB_DEVICE_LTM_ENABLE: 59 - s = "LTM Enable"; 60 - break; 61 - default: 62 - s = "UNKNOWN"; 63 - } s; }), 79 + usb_decode_device_feature(wValue), 64 80 wValue == USB_DEVICE_TEST_MODE ? 65 - ({ char *s; 66 - switch (wIndex) { 67 - case TEST_J: 68 - s = ": TEST_J"; 69 - break; 70 - case TEST_K: 71 - s = ": TEST_K"; 72 - break; 73 - case TEST_SE0_NAK: 74 - s = ": TEST_SE0_NAK"; 75 - break; 76 - case TEST_PACKET: 77 - s = ": TEST_PACKET"; 78 - break; 79 - case TEST_FORCE_EN: 80 - s = ": TEST_FORCE_EN"; 81 - break; 82 - default: 83 - s = ": UNKNOWN"; 84 - } s; }) : ""); 81 + usb_decode_test_mode(wIndex) : ""); 85 82 break; 86 83 case USB_RECIP_INTERFACE: 87 84 snprintf(str, size, "%s Interface Feature(%s)",