aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustavo A. R. Silva <gustavo@embeddedor.com>2018-07-04 09:22:11 -0400
committerAlex Deucher <alexander.deucher@amd.com>2018-07-05 17:40:03 -0400
commit6f3472a993e7cb63cde5d818dcabc8e42fc03744 (patch)
tree1bcb21e5c3ea25ff7e9b09419c40350040329d2e
parent4c1ac53eb867670883f1518f620b19c2fed7e516 (diff)
drm/amd/display/dc/dce: Fix multiple potential integer overflows
Add suffix ULL to constant 5 and cast variables target_pix_clk_khz and feedback_divider to uint64_t in order to avoid multiple potential integer overflows and give the compiler complete information about the proper arithmetic to use. Notice that such constant and variables are used in contexts that expect expressions of type uint64_t (64 bits, unsigned). The current casts to uint64_t effectively apply to each expression as a whole, but they do not prevent them from being evaluated using 32-bit arithmetic instead of 64-bit arithmetic. Also, once the expressions are properly evaluated using 64-bit arithmentic, there is no need for the parentheses that enclose them. Addresses-Coverity-ID: 1460245 ("Unintentional integer overflow") Addresses-Coverity-ID: 1460286 ("Unintentional integer overflow") Addresses-Coverity-ID: 1460401 ("Unintentional integer overflow") Fixes: 4562236b3bc0 ("drm/amd/dc: Add dc display driver (v2)") Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Harry Wentland <harry.wentland@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r--drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c b/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
index 88b09dd758ba..ca137757a69e 100644
--- a/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
+++ b/drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c
@@ -133,7 +133,7 @@ static bool calculate_fb_and_fractional_fb_divider(
133 uint64_t feedback_divider; 133 uint64_t feedback_divider;
134 134
135 feedback_divider = 135 feedback_divider =
136 (uint64_t)(target_pix_clk_khz * ref_divider * post_divider); 136 (uint64_t)target_pix_clk_khz * ref_divider * post_divider;
137 feedback_divider *= 10; 137 feedback_divider *= 10;
138 /* additional factor, since we divide by 10 afterwards */ 138 /* additional factor, since we divide by 10 afterwards */
139 feedback_divider *= (uint64_t)(calc_pll_cs->fract_fb_divider_factor); 139 feedback_divider *= (uint64_t)(calc_pll_cs->fract_fb_divider_factor);
@@ -145,8 +145,8 @@ static bool calculate_fb_and_fractional_fb_divider(
145 * of fractional feedback decimal point and the fractional FB Divider precision 145 * of fractional feedback decimal point and the fractional FB Divider precision
146 * is 2 then the equation becomes (ullfeedbackDivider + 5*100) / (10*100))*/ 146 * is 2 then the equation becomes (ullfeedbackDivider + 5*100) / (10*100))*/
147 147
148 feedback_divider += (uint64_t) 148 feedback_divider += 5ULL *
149 (5 * calc_pll_cs->fract_fb_divider_precision_factor); 149 calc_pll_cs->fract_fb_divider_precision_factor;
150 feedback_divider = 150 feedback_divider =
151 div_u64(feedback_divider, 151 div_u64(feedback_divider,
152 calc_pll_cs->fract_fb_divider_precision_factor * 10); 152 calc_pll_cs->fract_fb_divider_precision_factor * 10);
@@ -203,8 +203,8 @@ static bool calc_fb_divider_checking_tolerance(
203 &fract_feedback_divider); 203 &fract_feedback_divider);
204 204
205 /*Actual calculated value*/ 205 /*Actual calculated value*/
206 actual_calc_clk_khz = (uint64_t)(feedback_divider * 206 actual_calc_clk_khz = (uint64_t)feedback_divider *
207 calc_pll_cs->fract_fb_divider_factor) + 207 calc_pll_cs->fract_fb_divider_factor +
208 fract_feedback_divider; 208 fract_feedback_divider;
209 actual_calc_clk_khz *= calc_pll_cs->ref_freq_khz; 209 actual_calc_clk_khz *= calc_pll_cs->ref_freq_khz;
210 actual_calc_clk_khz = 210 actual_calc_clk_khz =