Skip to content

Commit e84cb60

Browse files
Boris Brezillonmripard
authored andcommitted
drm/sun4i: Fix an ulong overflow in the dotclock driver
The calculated ideal rate can easily overflow an unsigned long, thus making the best div selection buggy as soon as no ideal match is found before the overflow occurs. Fixes: 4731a72 ("drm/sun4i: request exact rates to our parents") Cc: <stable@vger.kernel.org> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> Link: https://patchwork.freedesktop.org/patch/msgid/20181018100250.12565-1-boris.brezillon@bootlin.com
1 parent 4364bcb commit e84cb60

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

drivers/gpu/drm/sun4i/sun4i_dotclock.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,19 @@ static long sun4i_dclk_round_rate(struct clk_hw *hw, unsigned long rate,
8181
int i;
8282

8383
for (i = tcon->dclk_min_div; i <= tcon->dclk_max_div; i++) {
84-
unsigned long ideal = rate * i;
84+
u64 ideal = (u64)rate * i;
8585
unsigned long rounded;
8686

87+
/*
88+
* ideal has overflowed the max value that can be stored in an
89+
* unsigned long, and every clk operation we might do on a
90+
* truncated u64 value will give us incorrect results.
91+
* Let's just stop there since bigger dividers will result in
92+
* the same overflow issue.
93+
*/
94+
if (ideal > ULONG_MAX)
95+
goto out;
96+
8797
rounded = clk_hw_round_rate(clk_hw_get_parent(hw),
8898
ideal);
8999

0 commit comments

Comments
 (0)