Skip to content

Commit f72429f

Browse files
pawellcdnsFelipe Balbi
authored and
Felipe Balbi
committed
usb: common: Simplify usb_decode_get_set_descriptor function.
Patch moves switch responsible for decoding descriptor type outside snprintf. It improves code readability a little. Signed-off-by: Pawel Laszczak <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent 010665b commit f72429f

File tree

1 file changed

+58
-55
lines changed

1 file changed

+58
-55
lines changed

drivers/usb/common/debug.c

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -105,62 +105,65 @@ static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest,
105105
__u16 wValue, __u16 wIndex,
106106
__u16 wLength, char *str, size_t size)
107107
{
108+
char *s;
109+
110+
switch (wValue >> 8) {
111+
case USB_DT_DEVICE:
112+
s = "Device";
113+
break;
114+
case USB_DT_CONFIG:
115+
s = "Configuration";
116+
break;
117+
case USB_DT_STRING:
118+
s = "String";
119+
break;
120+
case USB_DT_INTERFACE:
121+
s = "Interface";
122+
break;
123+
case USB_DT_ENDPOINT:
124+
s = "Endpoint";
125+
break;
126+
case USB_DT_DEVICE_QUALIFIER:
127+
s = "Device Qualifier";
128+
break;
129+
case USB_DT_OTHER_SPEED_CONFIG:
130+
s = "Other Speed Config";
131+
break;
132+
case USB_DT_INTERFACE_POWER:
133+
s = "Interface Power";
134+
break;
135+
case USB_DT_OTG:
136+
s = "OTG";
137+
break;
138+
case USB_DT_DEBUG:
139+
s = "Debug";
140+
break;
141+
case USB_DT_INTERFACE_ASSOCIATION:
142+
s = "Interface Association";
143+
break;
144+
case USB_DT_BOS:
145+
s = "BOS";
146+
break;
147+
case USB_DT_DEVICE_CAPABILITY:
148+
s = "Device Capability";
149+
break;
150+
case USB_DT_PIPE_USAGE:
151+
s = "Pipe Usage";
152+
break;
153+
case USB_DT_SS_ENDPOINT_COMP:
154+
s = "SS Endpoint Companion";
155+
break;
156+
case USB_DT_SSP_ISOC_ENDPOINT_COMP:
157+
s = "SSP Isochronous Endpoint Companion";
158+
break;
159+
default:
160+
s = "UNKNOWN";
161+
break;
162+
}
163+
108164
snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)",
109-
bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set",
110-
({ char *s;
111-
switch (wValue >> 8) {
112-
case USB_DT_DEVICE:
113-
s = "Device";
114-
break;
115-
case USB_DT_CONFIG:
116-
s = "Configuration";
117-
break;
118-
case USB_DT_STRING:
119-
s = "String";
120-
break;
121-
case USB_DT_INTERFACE:
122-
s = "Interface";
123-
break;
124-
case USB_DT_ENDPOINT:
125-
s = "Endpoint";
126-
break;
127-
case USB_DT_DEVICE_QUALIFIER:
128-
s = "Device Qualifier";
129-
break;
130-
case USB_DT_OTHER_SPEED_CONFIG:
131-
s = "Other Speed Config";
132-
break;
133-
case USB_DT_INTERFACE_POWER:
134-
s = "Interface Power";
135-
break;
136-
case USB_DT_OTG:
137-
s = "OTG";
138-
break;
139-
case USB_DT_DEBUG:
140-
s = "Debug";
141-
break;
142-
case USB_DT_INTERFACE_ASSOCIATION:
143-
s = "Interface Association";
144-
break;
145-
case USB_DT_BOS:
146-
s = "BOS";
147-
break;
148-
case USB_DT_DEVICE_CAPABILITY:
149-
s = "Device Capability";
150-
break;
151-
case USB_DT_PIPE_USAGE:
152-
s = "Pipe Usage";
153-
break;
154-
case USB_DT_SS_ENDPOINT_COMP:
155-
s = "SS Endpoint Companion";
156-
break;
157-
case USB_DT_SSP_ISOC_ENDPOINT_COMP:
158-
s = "SSP Isochronous Endpoint Companion";
159-
break;
160-
default:
161-
s = "UNKNOWN";
162-
break;
163-
} s; }), wValue & 0xff, wLength);
165+
bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set",
166+
s, wValue & 0xff, wLength);
164167
}
165168

166169
static void usb_decode_get_configuration(__u16 wLength, char *str, size_t size)

0 commit comments

Comments
 (0)