usb: xhci-mtk: check boundary before check tt
authorChunfeng Yun <chunfeng.yun@mediatek.com>
Tue, 17 Aug 2021 08:36:27 +0000 (16:36 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 26 Aug 2021 11:39:20 +0000 (13:39 +0200)
check_sch_tt() will access fs_bus_bw[] array, check boundary
firstly to avoid out-of-bounds issue.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Link: https://lore.kernel.org/r/1629189389-18779-7-git-send-email-chunfeng.yun@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/xhci-mtk-sch.c

index 10c0f0f6461fe1ebd4a33a553aa28e05654b1980..c2f13d69c607a6e161d4ac662ddcc7d7db77a2e2 100644 (file)
@@ -600,13 +600,14 @@ static int check_sch_bw(struct mu3h_sch_bw_info *sch_bw,
         * and find a microframe where its worst bandwidth is minimum.
         */
        for (offset = 0; offset < sch_ep->esit; offset++) {
-               ret = check_sch_tt(sch_ep, offset);
-               if (ret)
-                       continue;
 
                if ((offset + sch_ep->num_budget_microframes) > esit_boundary)
                        break;
 
+               ret = check_sch_tt(sch_ep, offset);
+               if (ret)
+                       continue;
+
                worst_bw = get_max_bw(sch_bw, sch_ep, offset);
                if (worst_bw > bw_boundary)
                        continue;