From: Alexandre Mergnat <amergnat@baylibre.com>
To: Shuijing Li <shuijing.li@mediatek.com>,
thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com
Cc: devicetree@vger.kernel.org, linux-pwm@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
Project_Global_Chrome_Upstream_Group@mediatek.com,
jitao.shi@mediatek.com
Subject: Re: [PATCH] pwm: mtk_disp: fix disp_pwm coverity issue
Date: Thu, 6 Jul 2023 14:29:11 +0200 [thread overview]
Message-ID: <55c3a448-e6c6-5e04-2cee-b2a18f0033e3@baylibre.com> (raw)
In-Reply-To: <20230706100454.28998-1-shuijing.li@mediatek.com>
On 06/07/2023 12:04, Shuijing Li wrote:
> There is a coverity issue in the original mtk_disp_pwm_get_state()
> function. In function call DIV64_U64_ROUND_UP, division by expression
> Which may be zero has undefined behavior.
> Fix this accordingly.
>
> Signed-off-by: Shuijing Li <shuijing.li@mediatek.com>
> ---
> drivers/pwm/pwm-mtk-disp.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c
> index 79e321e96f56..ca00058a6ef4 100644
> --- a/drivers/pwm/pwm-mtk-disp.c
> +++ b/drivers/pwm/pwm-mtk-disp.c
> @@ -196,6 +196,14 @@ static int mtk_disp_pwm_get_state(struct pwm_chip *chip,
> return err;
> }
>
> + rate = clk_get_rate(mdp->clk_main);
> + if (rate <= 0) {
> + dev_err(chip->dev, "Can't get rate: %pe\n", ERR_PTR(rate));
> + clk_disable_unprepare(mdp->clk_mm);
> + clk_disable_unprepare(mdp->clk_main);
> + return err;
> + }
> +
> /*
> * Apply DISP_PWM_DEBUG settings to choose whether to enable or disable
> * registers double buffer and manual commit to working register before
> @@ -206,7 +214,6 @@ static int mtk_disp_pwm_get_state(struct pwm_chip *chip,
> mdp->data->bls_debug_mask,
> mdp->data->bls_debug_mask);
>
> - rate = clk_get_rate(mdp->clk_main);
> con0 = readl(mdp->base + mdp->data->con0);
> con1 = readl(mdp->base + mdp->data->con1);
> pwm_en = readl(mdp->base + DISP_PWM_EN);
IMHO, it should be done int the function `mtk_disp_pwm_apply` too.
Do you agree ?
--
Regards,
Alexandre
next prev parent reply other threads:[~2023-07-06 12:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-06 10:04 [PATCH] pwm: mtk_disp: fix disp_pwm coverity issue Shuijing Li
2023-07-06 12:29 ` Alexandre Mergnat [this message]
2023-07-06 12:45 ` AngeloGioacchino Del Regno
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=55c3a448-e6c6-5e04-2cee-b2a18f0033e3@baylibre.com \
--to=amergnat@baylibre.com \
--cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=jitao.shi@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pwm@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=shuijing.li@mediatek.com \
--cc=thierry.reding@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
/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