Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp258144imm; Tue, 3 Jul 2018 18:36:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpccL438jIaZQR9f7unIoNl7C3vFY9Xd1SkhTt/wkLOayhO7XA9ISZFqTR27li/Zbi2E92Wg X-Received: by 2002:a17:902:8306:: with SMTP id bd6-v6mr62982plb.120.1530668161691; Tue, 03 Jul 2018 18:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530668161; cv=none; d=google.com; s=arc-20160816; b=nJ+9APP3v9mf4dcfWo16zR1MKETlJChmClTvBU9Zq1TSD4E+uADdMEfCpbyFUjvEix p91RTUzJ78CzzlRRU//xT0jfP7I9odoMxE77X56gy3NJ076MbM6FKAmtGULo9nmQvtL3 ow4HEELZRqr1RVS9dSuyEIv7EeuYP5bSsAgqLHHGmbYscgCfW75FPyiGMuFG1FPK3QwH TSHKSTP0SUjUyxPUFuwIYburHQ4OWDA3mRrEBY3yslkTj3Z+nI5d6wdC1+Lzs7VJj7wB HBJZbdgfqbxaVmXt6Dgb/wTeHvJEk3J/lALvjIC01oQhRR6waXUqwnCaiCxBSlHaWwMd bIqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date :arc-authentication-results; bh=/arNXzzUHEemMdlxx3L46rj322afI4CiUhEdiIQcS3o=; b=kUECItkEypGMZKUM5UMwgw+au2YoR2MDuqaxSSsWCD1XPCdUgr9CWuews/u6nLhUL/ qulkn0fIeGY3LtoR5VfJBAxxvlJbecx85aPfhVO7TOw/IyoIpTF+J1RBT2dlxL8f2Zyb KiBCuUwj95sIZtFtp23Eoij+kklnzyhFJBKl3X23FJgZeYdzBiSmQqT4TZCLeO6UELIo dI8DwrSvbGxycC/iv2D8TTpnoUYoUMaQwGLljPtpL4eo6QxtfmssNzlXmXP+zlluDu6K +TyG84GtSxCeLEYjJiGnHfo9vR8CY2zifeIo1T7SDxuDZKWvCh8gY03VcdGhnu4ciS8p nulg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4-v6si2075905pgv.624.2018.07.03.18.35.33; Tue, 03 Jul 2018 18:36:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932499AbeGDBed (ORCPT + 99 others); Tue, 3 Jul 2018 21:34:33 -0400 Received: from gateway36.websitewelcome.com ([192.185.179.26]:24967 "EHLO gateway36.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932364AbeGDBec (ORCPT ); Tue, 3 Jul 2018 21:34:32 -0400 X-Greylist: delayed 1266 seconds by postgrey-1.27 at vger.kernel.org; Tue, 03 Jul 2018 21:34:32 EDT Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 38D33400C723F for ; Tue, 3 Jul 2018 19:14:11 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id aWLzf0CS2bXuJaWMAfAXlS; Tue, 03 Jul 2018 20:13:25 -0500 X-Authority-Reason: nr=8 Received: from [189.250.65.56] (port=54074 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1faWLy-000xZM-6U; Tue, 03 Jul 2018 20:13:06 -0500 Date: Tue, 3 Jul 2018 20:13:05 -0500 From: "Gustavo A. R. Silva" To: Alex Deucher , Christian =?iso-8859-1?Q?K=F6nig?= , "David (ChunMing) Zhou" , David Airlie Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] drm/amd/display/dc/dce: Fix multiple potential integer overflows Message-ID: <20180704011305.GA15742@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.65.56 X-Source-L: No X-Exim-ID: 1faWLy-000xZM-6U X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.65.56]:54074 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 8 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/gpu/drm/amd/display/dc/dce/dce_clock_source.c | 10 +++++----- 1 file 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 88b09dd..715d737 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( uint64_t feedback_divider; feedback_divider = - (uint64_t)(target_pix_clk_khz * ref_divider * post_divider); + (uint64_t)target_pix_clk_khz * ref_divider * post_divider; feedback_divider *= 10; /* additional factor, since we divide by 10 afterwards */ feedback_divider *= (uint64_t)(calc_pll_cs->fract_fb_divider_factor); @@ -145,8 +145,8 @@ static bool calculate_fb_and_fractional_fb_divider( * of fractional feedback decimal point and the fractional FB Divider precision * is 2 then the equation becomes (ullfeedbackDivider + 5*100) / (10*100))*/ - feedback_divider += (uint64_t) - (5 * calc_pll_cs->fract_fb_divider_precision_factor); + feedback_divider += 5UL * + calc_pll_cs->fract_fb_divider_precision_factor; feedback_divider = div_u64(feedback_divider, calc_pll_cs->fract_fb_divider_precision_factor * 10); @@ -203,8 +203,8 @@ static bool calc_fb_divider_checking_tolerance( &fract_feedback_divider); /*Actual calculated value*/ - actual_calc_clk_khz = (uint64_t)(feedback_divider * - calc_pll_cs->fract_fb_divider_factor) + + actual_calc_clk_khz = (uint64_t)feedback_divider * + calc_pll_cs->fract_fb_divider_factor + fract_feedback_divider; actual_calc_clk_khz *= calc_pll_cs->ref_freq_khz; actual_calc_clk_khz = -- 2.7.4