usb: cdnsp: fix cdnsp_decode_trb function to properly handle ret value
[ Upstream commit 03db9289b5
]
Variable ret in function cdnsp_decode_trb is initialized but not
used. To fix this compiler warning patch adds checking whether the
data buffer has not been overflowed.
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Pawel Laszczak <pawell@cadence.com>
Link: https://lore.kernel.org/r/20220112053237.14309-1-pawell@gli-login.cadence.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Родитель
c27576bbbe
Коммит
052fb1c9dd
|
@ -182,14 +182,14 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
int ep_id = TRB_TO_EP_INDEX(field3) - 1;
|
||||
int type = TRB_FIELD_TO_TYPE(field3);
|
||||
unsigned int ep_num;
|
||||
int ret = 0;
|
||||
int ret;
|
||||
u32 temp;
|
||||
|
||||
ep_num = DIV_ROUND_UP(ep_id, 2);
|
||||
|
||||
switch (type) {
|
||||
case TRB_LINK:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"LINK %08x%08x intr %ld type '%s' flags %c:%c:%c:%c",
|
||||
field1, field0, GET_INTR_TARGET(field2),
|
||||
cdnsp_trb_type_string(type),
|
||||
|
@ -202,7 +202,7 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
case TRB_COMPLETION:
|
||||
case TRB_PORT_STATUS:
|
||||
case TRB_HC_EVENT:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"ep%d%s(%d) type '%s' TRB %08x%08x status '%s'"
|
||||
" len %ld slot %ld flags %c:%c",
|
||||
ep_num, ep_id % 2 ? "out" : "in",
|
||||
|
@ -214,12 +214,12 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
case TRB_MFINDEX_WRAP:
|
||||
ret += snprintf(str, size, "%s: flags %c",
|
||||
ret = snprintf(str, size, "%s: flags %c",
|
||||
cdnsp_trb_type_string(type),
|
||||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
case TRB_SETUP:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"type '%s' bRequestType %02x bRequest %02x "
|
||||
"wValue %02x%02x wIndex %02x%02x wLength %d "
|
||||
"length %ld TD size %ld intr %ld Setup ID %ld "
|
||||
|
@ -241,7 +241,7 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
case TRB_DATA:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"type '%s' Buffer %08x%08x length %ld TD size %ld "
|
||||
"intr %ld flags %c:%c:%c:%c:%c:%c:%c",
|
||||
cdnsp_trb_type_string(type),
|
||||
|
@ -257,7 +257,7 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
case TRB_STATUS:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"Buffer %08x%08x length %ld TD size %ld intr"
|
||||
"%ld type '%s' flags %c:%c:%c:%c",
|
||||
field1, field0, TRB_LEN(field2),
|
||||
|
@ -273,7 +273,7 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
case TRB_ISOC:
|
||||
case TRB_EVENT_DATA:
|
||||
case TRB_TR_NOOP:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"type '%s' Buffer %08x%08x length %ld "
|
||||
"TD size %ld intr %ld "
|
||||
"flags %c:%c:%c:%c:%c:%c:%c:%c:%c",
|
||||
|
@ -293,18 +293,18 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
break;
|
||||
case TRB_CMD_NOOP:
|
||||
case TRB_ENABLE_SLOT:
|
||||
ret += snprintf(str, size, "%s: flags %c",
|
||||
ret = snprintf(str, size, "%s: flags %c",
|
||||
cdnsp_trb_type_string(type),
|
||||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
case TRB_DISABLE_SLOT:
|
||||
ret += snprintf(str, size, "%s: slot %ld flags %c",
|
||||
ret = snprintf(str, size, "%s: slot %ld flags %c",
|
||||
cdnsp_trb_type_string(type),
|
||||
TRB_TO_SLOT_ID(field3),
|
||||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
case TRB_ADDR_DEV:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"%s: ctx %08x%08x slot %ld flags %c:%c",
|
||||
cdnsp_trb_type_string(type), field1, field0,
|
||||
TRB_TO_SLOT_ID(field3),
|
||||
|
@ -312,7 +312,7 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
case TRB_CONFIG_EP:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"%s: ctx %08x%08x slot %ld flags %c:%c",
|
||||
cdnsp_trb_type_string(type), field1, field0,
|
||||
TRB_TO_SLOT_ID(field3),
|
||||
|
@ -320,7 +320,7 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
case TRB_EVAL_CONTEXT:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"%s: ctx %08x%08x slot %ld flags %c",
|
||||
cdnsp_trb_type_string(type), field1, field0,
|
||||
TRB_TO_SLOT_ID(field3),
|
||||
|
@ -329,7 +329,7 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
case TRB_RESET_EP:
|
||||
case TRB_HALT_ENDPOINT:
|
||||
case TRB_FLUSH_ENDPOINT:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"%s: ep%d%s(%d) ctx %08x%08x slot %ld flags %c",
|
||||
cdnsp_trb_type_string(type),
|
||||
ep_num, ep_id % 2 ? "out" : "in",
|
||||
|
@ -338,7 +338,7 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
case TRB_STOP_RING:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"%s: ep%d%s(%d) slot %ld sp %d flags %c",
|
||||
cdnsp_trb_type_string(type),
|
||||
ep_num, ep_id % 2 ? "out" : "in",
|
||||
|
@ -348,7 +348,7 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
case TRB_SET_DEQ:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"%s: ep%d%s(%d) deq %08x%08x stream %ld slot %ld flags %c",
|
||||
cdnsp_trb_type_string(type),
|
||||
ep_num, ep_id % 2 ? "out" : "in",
|
||||
|
@ -358,7 +358,7 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
case TRB_RESET_DEV:
|
||||
ret += snprintf(str, size, "%s: slot %ld flags %c",
|
||||
ret = snprintf(str, size, "%s: slot %ld flags %c",
|
||||
cdnsp_trb_type_string(type),
|
||||
TRB_TO_SLOT_ID(field3),
|
||||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
|
@ -366,7 +366,7 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
case TRB_ENDPOINT_NRDY:
|
||||
temp = TRB_TO_HOST_STREAM(field2);
|
||||
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"%s: ep%d%s(%d) H_SID %x%s%s D_SID %lx flags %c:%c",
|
||||
cdnsp_trb_type_string(type),
|
||||
ep_num, ep_id % 2 ? "out" : "in",
|
||||
|
@ -378,12 +378,15 @@ static inline const char *cdnsp_decode_trb(char *str, size_t size, u32 field0,
|
|||
field3 & TRB_CYCLE ? 'C' : 'c');
|
||||
break;
|
||||
default:
|
||||
ret += snprintf(str, size,
|
||||
ret = snprintf(str, size,
|
||||
"type '%s' -> raw %08x %08x %08x %08x",
|
||||
cdnsp_trb_type_string(type),
|
||||
field0, field1, field2, field3);
|
||||
}
|
||||
|
||||
if (ret >= size)
|
||||
pr_info("CDNSP: buffer overflowed.\n");
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче