epnum is used as an index into an array. The limit check for this index
should be performed before using it to access an element in the array to
prevent possible bounds overrun.
This issue was found by Smatch.
Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
if (!epnum) {
result[0] = 0;
break;
+ } else if (epnum >= MUSB_C_NUM_EPS) {
+ handled = -EINVAL;
+ break;
}
is_in = epnum & USB_DIR_IN;
}
regs = musb->endpoints[epnum].regs;
- if (epnum >= MUSB_C_NUM_EPS || !ep->desc) {
+ if (!ep->desc) {
handled = -EINVAL;
break;
}