Skip to content

Commit 010665b

Browse files
pawellcdnsFelipe Balbi
authored andcommitted
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 <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent 91f255a commit 010665b

File tree

1 file changed

+43
-46
lines changed

1 file changed

+43
-46
lines changed

drivers/usb/common/debug.c

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,58 +30,55 @@ static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex,
3030
}
3131
}
3232

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)
3674
{
3775
switch (bRequestType & USB_RECIP_MASK) {
3876
case USB_RECIP_DEVICE:
3977
snprintf(str, size, "%s Device Feature(%s%s)",
4078
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),
6480
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) : "");
8582
break;
8683
case USB_RECIP_INTERFACE:
8784
snprintf(str, size, "%s Interface Feature(%s)",

0 commit comments

Comments
 (0)