Skip to contentSkip to conversation

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

PATCH Applied Su Hui 2 participants 3 messages Jun 8, 2023 – Jun 13, 2023

Subsystems (4)
lore
Share & tools
lore

Su Hui

author
#0 lore raw

PATCH v3 1/1 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")
---
 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +4 -0
index 7a748785c545..4676cf2900df 100644
@@ -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));
 
Signature · 1 line
2.30.2
reviewer Reviewed-by on v3 1/1
#1 lore raw

Hi,

Quoted 14 lines · Su Hui

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

Fixes cea86c5bb442 ("drm/bridge: ti-sn65dsi86: Implement the pwm_chip")
---
 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +0 -0
index 7a748785c545..4676cf2900df 100644

drivers/gpu/drm/bridge/ti-sn65dsi86.c static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata) · line 304

Quoted 7 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +4 -0
@@ -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!

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

-Doug

reviewer Applied
#2 lore raw

Hi,

Quoted 28 lines · Doug Anderson

Hi,

Quoted 14 lines · Su Hui

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

Fixes cea86c5bb442 ("drm/bridge: ti-sn65dsi86: Implement the pwm_chip")
---
 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +0 -0
index 7a748785c545..4676cf2900df 100644

drivers/gpu/drm/bridge/ti-sn65dsi86.c static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata) · line 304

Quoted 7 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +4 -0
@@ -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!

Quoted 4 lines

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