2023-06-08 01:44:02

by Su Hui

[permalink] [raw]
Subject: [PATCH v3] drm/bridge: ti-sn65dsi86: Avoid possible buffer overflow

Smatch error:buffer overflow 'ti_sn_bridge_refclk_lut' 5 <= 5.

Fixes: cea86c5bb442 ("drm/bridge: ti-sn65dsi86: Implement the pwm_chip")
Signed-off-by: Su Hui <[email protected]>
---
drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
index 7a748785c545..4676cf2900df 100644
--- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
+++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
@@ -298,6 +298,10 @@ static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata)
if (refclk_lut[i] == refclk_rate)
break;

+ /* avoid buffer overflow and "1" is the default rate in the datasheet. */
+ if (i >= refclk_lut_size)
+ i = 1;
+
regmap_update_bits(pdata->regmap, SN_DPPLL_SRC_REG, REFCLK_FREQ_MASK,
REFCLK_FREQ(i));

--
2.30.2



2023-06-08 15:42:33

by Doug Anderson

[permalink] [raw]
Subject: Re: [PATCH v3] drm/bridge: ti-sn65dsi86: Avoid possible buffer overflow

Hi,

On Wed, Jun 7, 2023 at 6:25 PM Su Hui <[email protected]> wrote:
>
> Smatch error:buffer overflow 'ti_sn_bridge_refclk_lut' 5 <= 5.
>
> Fixes: cea86c5bb442 ("drm/bridge: ti-sn65dsi86: Implement the pwm_chip")
> Signed-off-by: Su Hui <[email protected]>
> ---
> drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> index 7a748785c545..4676cf2900df 100644
> --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> @@ -298,6 +298,10 @@ static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata)
> if (refclk_lut[i] == refclk_rate)
> break;
>
> + /* avoid buffer overflow and "1" is the default rate in the datasheet. */
> + if (i >= refclk_lut_size)
> + i = 1;
> +

Looks great now, thanks!

Reviewed-by: Douglas Anderson <[email protected]>

Unless someone beats me to it or objects, I'll plan to commit this to
drm-misc-fixes early next week.

-Doug

2023-06-13 18:18:11

by Doug Anderson

[permalink] [raw]
Subject: Re: [PATCH v3] drm/bridge: ti-sn65dsi86: Avoid possible buffer overflow

Hi,

On Thu, Jun 8, 2023 at 8:15 AM Doug Anderson <[email protected]> wrote:
>
> Hi,
>
> On Wed, Jun 7, 2023 at 6:25 PM Su Hui <[email protected]> wrote:
> >
> > Smatch error:buffer overflow 'ti_sn_bridge_refclk_lut' 5 <= 5.
> >
> > Fixes: cea86c5bb442 ("drm/bridge: ti-sn65dsi86: Implement the pwm_chip")
> > Signed-off-by: Su Hui <[email protected]>
> > ---
> > drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> > index 7a748785c545..4676cf2900df 100644
> > --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> > +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> > @@ -298,6 +298,10 @@ static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata)
> > if (refclk_lut[i] == refclk_rate)
> > break;
> >
> > + /* avoid buffer overflow and "1" is the default rate in the datasheet. */
> > + if (i >= refclk_lut_size)
> > + i = 1;
> > +
>
> Looks great now, thanks!
>
> Reviewed-by: Douglas Anderson <[email protected]>
>
> Unless someone beats me to it or objects, I'll plan to commit this to
> drm-misc-fixes early next week.

Pushed to drm-misc-fixes:

95011f267c44 drm/bridge: ti-sn65dsi86: Avoid possible buffer overflow