usb: dwc3-msm: Add explicit out-of-bounds check before array access

Explicitly adding out-of-bounds check to ensure bus_vote_values and
mdwc->dbm_ep_num_mapping use indices within their specified range.

Change-Id: I196f69011f2c2392477e11b6eb19a395bb753dc5
Signed-off-by: Ronak Vijay Raheja <rraheja@codeaurora.org>
This commit is contained in:
Ronak Vijay Raheja 2020-09-11 13:15:30 -07:00 • committed by Gerrit - the friendly Code Review server
commit 182eba5d94

View file

@ -658,7 +658,7 @@ static int dbm_get_num_of_eps_configured(struct dwc3_msm *mdwc)
int i;
int count = 0;
for (i = 0; i < mdwc->dbm_num_eps; i++)
for (i = 0; i < min(mdwc->dbm_num_eps, DBM_1_5_NUM_EP); i++)
if (mdwc->dbm_ep_num_mapping[i])
count++;
@ -2773,9 +2773,9 @@ static int dwc3_msm_update_bus_bw(struct dwc3_msm *mdwc, enum bus_vote bv)
* set it to _NONE irrespective of the requested vote
* from userspace.
*/
if (bv >= BUS_VOTE_MAX)
bv_index = mdwc->default_bus_vote;
else if (bv == BUS_VOTE_NONE)
if (bv_index >= BUS_VOTE_MAX)
bv_index = BUS_VOTE_MAX - 1;
else if (bv_index < BUS_VOTE_NONE)
bv_index = BUS_VOTE_NONE;
for (i = 0; i < ARRAY_SIZE(mdwc->icc_paths); i++) {