drm: radeon: fix sign bug
Subsystems (3)
PATCH 1/1 drm: radeon: fix sign bug
The "error" variable is unsigned so it's never less than zero. I changed it to check if (freq < current_freq) directly.
"best_error" is also unsigned so "best_error - 100" could be a large number instead of a negative. Since "error" is unsigned it is never less than a negative and so the cases where "best_error" is less than or equal to 100 are false.
drivers/gpu/drm/radeon/radeon_display.c +5 -3
@@ -558,15 +558,17 @@ static void radeon_compute_pll_legacy(struct radeon_pll *pll, current_freq =radeon_div (tmp, ref_div * post_div);if (pll->flags &RADEON_PLL_PREFER_CLOSEST_LOWER ) { - error = freq - current_freq; - error = error <0 ?0xffffffff : error; +if (freq < current_freq) + error =0xffffffff ; +else + error = freq - current_freq; }else error =abs (current_freq - freq); vco_diff =abs (vco - best_vco);if ((best_vco =0 && error < best_error) || (best_vco !=0 && - (error < best_error -100 || + ((best_error >100 && error < best_error -100 ) || (abs (error - best_error) <100 && vco_diff < best_vco_diff)))) { best_post_div = post_div; best_ref_div = ref_div;
Quoted 10 lines · Dan Carpenter
The "error" variable is unsigned so it's never less than zero. I changed it to check if (freq <
current_freq) directly."
best_error" is also unsigned so "best_error- 100" could be a large number instead of a negative. Since "error" is unsigned it is never less than a negative and so the cases where "best_error" is less than or equal to 100 are false.Signed-off-by Dan Carpenter <[email protected]>
This looks good Dan. Dave, please apply,
Quoted 18 lines
drivers/gpu/drm/radeon/radeon_display.c +4
-2@@ -558,15 +558,17 @@ static void radeon_compute_pll_legacy(struct radeon_pll *pll, current_freq = radeon_div(tmp, ref_div * post_div); if (pll->flags & RADEON_PLL_PREFER_CLOSEST_LOWER) { - error = freq - current_freq; - error = error < 0 ? 0xffffffff : error; + if (freq < current_freq) + error = 0xffffffff; + else + error = freq - current_freq; } else error = abs(current_freq - freq); vco_diff = abs(vco - best_vco);
Quoted 8 lines
if ((
best_vco= 0 && error <best_error) || (best_vco!= 0 &&
- (error <best_error- 100 ||
+ ((best_error > 100 && error <best_error- 100) || (abs(error - best_error)< 100 &&vco_diff<best_vco_diff)))) {best_post_div=post_div;
best_ref_div =ref_div;
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html