Commit b32196e3 authored by Colin Ian King's avatar Colin Ian King Committed by Greg Kroah-Hartman

usb: dwc3: debug: fix string position formatting mixup with ret and len

Currently the string formatting is mixing up the offset of ret and
len. Re-work the code to use just len, remove ret and use scnprintf
instead of snprintf and len position accumulation where required.
Remove the -ve return check since scnprintf never returns a failure
-ve size. Also break overly long lines to clean up checkpatch
warnings.

Addresses-Coverity: ("Unused value")
Fixes: 1381a511 ("usb: dwc3: debug: purge usage of strcat")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Reviewed-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20200210095139.328711-1-colin.king@canonical.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a4a60194
...@@ -256,86 +256,77 @@ static inline const char *dwc3_ep_event_string(char *str, size_t size, ...@@ -256,86 +256,77 @@ static inline const char *dwc3_ep_event_string(char *str, size_t size,
u8 epnum = event->endpoint_number; u8 epnum = event->endpoint_number;
size_t len; size_t len;
int status; int status;
int ret;
ret = snprintf(str, size, "ep%d%s: ", epnum >> 1, len = scnprintf(str, size, "ep%d%s: ", epnum >> 1,
(epnum & 1) ? "in" : "out"); (epnum & 1) ? "in" : "out");
if (ret < 0)
return "UNKNOWN";
status = event->status; status = event->status;
switch (event->endpoint_event) { switch (event->endpoint_event) {
case DWC3_DEPEVT_XFERCOMPLETE: case DWC3_DEPEVT_XFERCOMPLETE:
len = strlen(str); len += scnprintf(str + len, size - len,
snprintf(str + len, size - len, "Transfer Complete (%c%c%c)", "Transfer Complete (%c%c%c)",
status & DEPEVT_STATUS_SHORT ? 'S' : 's', status & DEPEVT_STATUS_SHORT ? 'S' : 's',
status & DEPEVT_STATUS_IOC ? 'I' : 'i', status & DEPEVT_STATUS_IOC ? 'I' : 'i',
status & DEPEVT_STATUS_LST ? 'L' : 'l'); status & DEPEVT_STATUS_LST ? 'L' : 'l');
len = strlen(str);
if (epnum <= 1) if (epnum <= 1)
snprintf(str + len, size - len, " [%s]", scnprintf(str + len, size - len, " [%s]",
dwc3_ep0_state_string(ep0state)); dwc3_ep0_state_string(ep0state));
break; break;
case DWC3_DEPEVT_XFERINPROGRESS: case DWC3_DEPEVT_XFERINPROGRESS:
len = strlen(str); scnprintf(str + len, size - len,
"Transfer In Progress [%d] (%c%c%c)",
snprintf(str + len, size - len, "Transfer In Progress [%d] (%c%c%c)",
event->parameters, event->parameters,
status & DEPEVT_STATUS_SHORT ? 'S' : 's', status & DEPEVT_STATUS_SHORT ? 'S' : 's',
status & DEPEVT_STATUS_IOC ? 'I' : 'i', status & DEPEVT_STATUS_IOC ? 'I' : 'i',
status & DEPEVT_STATUS_LST ? 'M' : 'm'); status & DEPEVT_STATUS_LST ? 'M' : 'm');
break; break;
case DWC3_DEPEVT_XFERNOTREADY: case DWC3_DEPEVT_XFERNOTREADY:
len = strlen(str); len += scnprintf(str + len, size - len,
"Transfer Not Ready [%d]%s",
snprintf(str + len, size - len, "Transfer Not Ready [%d]%s",
event->parameters, event->parameters,
status & DEPEVT_STATUS_TRANSFER_ACTIVE ? status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
" (Active)" : " (Not Active)"); " (Active)" : " (Not Active)");
len = strlen(str);
/* Control Endpoints */ /* Control Endpoints */
if (epnum <= 1) { if (epnum <= 1) {
int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status); int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
switch (phase) { switch (phase) {
case DEPEVT_STATUS_CONTROL_DATA: case DEPEVT_STATUS_CONTROL_DATA:
snprintf(str + ret, size - ret, scnprintf(str + len, size - len,
" [Data Phase]"); " [Data Phase]");
break; break;
case DEPEVT_STATUS_CONTROL_STATUS: case DEPEVT_STATUS_CONTROL_STATUS:
snprintf(str + ret, size - ret, scnprintf(str + len, size - len,
" [Status Phase]"); " [Status Phase]");
} }
} }
break; break;
case DWC3_DEPEVT_RXTXFIFOEVT: case DWC3_DEPEVT_RXTXFIFOEVT:
snprintf(str + ret, size - ret, "FIFO"); scnprintf(str + len, size - len, "FIFO");
break; break;
case DWC3_DEPEVT_STREAMEVT: case DWC3_DEPEVT_STREAMEVT:
status = event->status; status = event->status;
switch (status) { switch (status) {
case DEPEVT_STREAMEVT_FOUND: case DEPEVT_STREAMEVT_FOUND:
snprintf(str + ret, size - ret, " Stream %d Found", scnprintf(str + len, size - len, " Stream %d Found",
event->parameters); event->parameters);
break; break;
case DEPEVT_STREAMEVT_NOTFOUND: case DEPEVT_STREAMEVT_NOTFOUND:
default: default:
snprintf(str + ret, size - ret, " Stream Not Found"); scnprintf(str + len, size - len, " Stream Not Found");
break; break;
} }
break; break;
case DWC3_DEPEVT_EPCMDCMPLT: case DWC3_DEPEVT_EPCMDCMPLT:
snprintf(str + ret, size - ret, "Endpoint Command Complete"); scnprintf(str + len, size - len, "Endpoint Command Complete");
break; break;
default: default:
snprintf(str, size, "UNKNOWN"); scnprintf(str + len, size - len, "UNKNOWN");
} }
return str; return str;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment