Skip to content

Commit 6c0473c

Browse files
Nikita Zhandarovichgregkh
authored andcommitted
drm/i915: Fix possible int overflow in skl_ddi_calculate_wrpll()
commit 5b51157 upstream. On the off chance that clock value ends up being too high (by means of skl_ddi_calculate_wrpll() having been called with big enough value of crtc_state->port_clock * 1000), one possible consequence may be that the result will not be able to fit into signed int. Fix this issue by moving conversion of clock parameter from kHz to Hz into the body of skl_ddi_calculate_wrpll(), as well as casting the same parameter to u64 type while calculating the value for AFE clock. This both mitigates the overflow problem and avoids possible erroneous integer promotion mishaps. Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE. Fixes: 82d3543 ("drm/i915/skl: Implementation of SKL DPLL programming") Cc: [email protected] Signed-off-by: Nikita Zhandarovich <[email protected]> Reviewed-by: Jani Nikula <[email protected]> Signed-off-by: Jani Nikula <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 833cf12) Signed-off-by: Joonas Lahtinen <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a62c981 commit 6c0473c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/gpu/drm/i915/display/intel_dpll_mgr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ static void skl_wrpll_params_populate(struct skl_wrpll_params *params,
15561556
}
15571557

15581558
static int
1559-
skl_ddi_calculate_wrpll(int clock /* in Hz */,
1559+
skl_ddi_calculate_wrpll(int clock,
15601560
int ref_clock,
15611561
struct skl_wrpll_params *wrpll_params)
15621562
{
@@ -1581,7 +1581,7 @@ skl_ddi_calculate_wrpll(int clock /* in Hz */,
15811581
};
15821582
unsigned int dco, d, i;
15831583
unsigned int p0, p1, p2;
1584-
u64 afe_clock = clock * 5; /* AFE Clock is 5x Pixel clock */
1584+
u64 afe_clock = (u64)clock * 1000 * 5; /* AFE Clock is 5x Pixel clock, in Hz */
15851585

15861586
for (d = 0; d < ARRAY_SIZE(dividers); d++) {
15871587
for (dco = 0; dco < ARRAY_SIZE(dco_central_freq); dco++) {
@@ -1713,7 +1713,7 @@ static int skl_ddi_hdmi_pll_dividers(struct intel_crtc_state *crtc_state)
17131713

17141714
ctrl1 |= DPLL_CTRL1_HDMI_MODE(0);
17151715

1716-
ret = skl_ddi_calculate_wrpll(crtc_state->port_clock * 1000,
1716+
ret = skl_ddi_calculate_wrpll(crtc_state->port_clock,
17171717
i915->display.dpll.ref_clks.nssc, &wrpll_params);
17181718
if (ret)
17191719
return ret;

0 commit comments

Comments
 (0)