From: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
To: Tim Gardner <tim.gardner@canonical.com>, dri-devel@lists.freedesktop.org
Cc: Rob Clark <robdclark@gmail.com>, Sean Paul <sean@poorly.run>,
David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
Abhinav Kumar <abhinavk@codeaurora.org>,
linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/msm/dsi: prevent unintentional integer overflow in dsi_pll_28nm_clk_recalc_rate()
Date: Sat, 2 Oct 2021 01:44:38 +0300 [thread overview]
Message-ID: <2f625866-89d0-3bc7-2618-2e01884d003d@linaro.org> (raw)
In-Reply-To: <20210929175134.15808-1-tim.gardner@canonical.com>
On 29/09/2021 20:51, Tim Gardner wrote:
> Coverity warns of an unintentional integer overflow
>
> CID 120715 (#1 of 1): Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
> overflow_before_widen: Potentially overflowing expression ref_clk * sdm_byp_div
> with type unsigned int (32 bits, unsigned) is evaluated using 32-bit arithmetic,
> and then used in a context that expects an expression of type unsigned long
> (64 bits, unsigned).
> To avoid overflow, cast either ref_clk or sdm_byp_div to type unsigned long.
> 263 vco_rate = ref_clk * sdm_byp_div;
>
> Fix this and another possible overflow by casting ref_clk to unsigned long.
Changing ref_clk from u32 to unsigned long would be a more simple and
elegant way of fixing this issue. Could you please update your patch?
>
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Cc: Abhinav Kumar <abhinavk@codeaurora.org>
> Cc: linux-arm-msm@vger.kernel.org
> Cc: dri-devel@lists.freedesktop.org
> Cc: freedreno@lists.freedesktop.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
> ---
> drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
> index 2da673a2add6..cfe4b30eb96d 100644
> --- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
> +++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
> @@ -260,7 +260,7 @@ static unsigned long dsi_pll_28nm_clk_recalc_rate(struct clk_hw *hw,
> sdm_byp_div = FIELD(
> dsi_phy_read(base + REG_DSI_28nm_PHY_PLL_SDM_CFG0),
> DSI_28nm_PHY_PLL_SDM_CFG0_BYP_DIV) + 1;
> - vco_rate = ref_clk * sdm_byp_div;
> + vco_rate = (unsigned long)ref_clk * sdm_byp_div;
> } else {
> /* sdm mode */
> sdm_dc_off = FIELD(
> @@ -274,7 +274,7 @@ static unsigned long dsi_pll_28nm_clk_recalc_rate(struct clk_hw *hw,
> sdm_freq_seed = (sdm3 << 8) | sdm2;
> DBG("sdm_freq_seed = %d", sdm_freq_seed);
>
> - vco_rate = (ref_clk * (sdm_dc_off + 1)) +
> + vco_rate = ((unsigned long)ref_clk * (sdm_dc_off + 1)) +
> mult_frac(ref_clk, sdm_freq_seed, BIT(16));
> DBG("vco rate = %lu", vco_rate);
> }
>
--
With best wishes
Dmitry
prev parent reply other threads:[~2021-10-01 22:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-29 17:51 [PATCH] drm/msm/dsi: prevent unintentional integer overflow in dsi_pll_28nm_clk_recalc_rate() Tim Gardner
2021-10-01 22:44 ` Dmitry Baryshkov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2f625866-89d0-3bc7-2618-2e01884d003d@linaro.org \
--to=dmitry.baryshkov@linaro.org \
--cc=abhinavk@codeaurora.org \
--cc=airlied@linux.ie \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robdclark@gmail.com \
--cc=sean@poorly.run \
--cc=tim.gardner@canonical.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).