diff mbox series

[09/11] usb: xhci-mtk: check boundary before check tt

Message ID 1627635002-24521-9-git-send-email-chunfeng.yun@mediatek.com
State Superseded
Headers show
Series [01/11] dt-bindings: usb: mtk-xhci: add support property 'tpl-support' | expand

Commit Message

Chunfeng Yun (云春峰) July 30, 2021, 8:50 a.m. UTC
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>
---
 drivers/usb/host/xhci-mtk-sch.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Ikjoon Jang Aug. 9, 2021, 7:32 a.m. UTC | #1
Hi Chunfeng,

On Fri, Jul 30, 2021 at 4:50 PM Chunfeng Yun <chunfeng.yun@mediatek.com> wrote:
>
> 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>
> ---
>  drivers/usb/host/xhci-mtk-sch.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
> index 10c0f0f6461f..c2f13d69c607 100644
> --- a/drivers/usb/host/xhci-mtk-sch.c
> +++ b/drivers/usb/host/xhci-mtk-sch.c
> @@ -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;

Instead of dropping it,
I'm wondering if it should be checked against (offset & 63) == 0 when it's 64?

>
> +               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;
> --
> 2.18.0
>
Chunfeng Yun (云春峰) Aug. 11, 2021, 8:18 a.m. UTC | #2
On Mon, 2021-08-09 at 15:32 +0800, Ikjoon Jang wrote:
> Hi Chunfeng,

> 

> On Fri, Jul 30, 2021 at 4:50 PM Chunfeng Yun <

> chunfeng.yun@mediatek.com> wrote:

> > 

> > 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>

> > ---

> >  drivers/usb/host/xhci-mtk-sch.c | 7 ++++---

> >  1 file changed, 4 insertions(+), 3 deletions(-)

> > 

> > diff --git a/drivers/usb/host/xhci-mtk-sch.c

> > b/drivers/usb/host/xhci-mtk-sch.c

> > index 10c0f0f6461f..c2f13d69c607 100644

> > --- a/drivers/usb/host/xhci-mtk-sch.c

> > +++ b/drivers/usb/host/xhci-mtk-sch.c

> > @@ -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;

> 

> Instead of dropping it,

> I'm wondering if it should be checked against (offset & 63) == 0 when

> it's 64?

No, sch_ep->esit already ensure it, it's <= 64, see get_esit()

> 

> > 

> > +               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;

> > --

> > 2.18.0

> >
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
index 10c0f0f6461f..c2f13d69c607 100644
--- a/drivers/usb/host/xhci-mtk-sch.c
+++ b/drivers/usb/host/xhci-mtk-sch.c
@@ -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;