public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Aleksandr Mishin <amishin@t-argos.ru>,
	Mike Looijmans <mike.looijmans@topic.nl>
Cc: Aleksandr Mishin <amishin@t-argos.ru>,
	Michael Turquette <mturquette@baylibre.com>,
	linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org, Maxime Ripard <mripard@kernel.org>
Subject: Re: [PATCH] clk: si5341: Prevent division by zero in si5341_output_clk_determine_rate()
Date: Thu, 19 Sep 2024 03:35:20 -0700	[thread overview]
Message-ID: <53f1cb2aefeb360002cd840cb8997ae3.sboyd@kernel.org> (raw)
In-Reply-To: <20240917075250.19333-1-amishin@t-argos.ru>

Quoting Aleksandr Mishin (2024-09-17 00:52:50)
> In si5341_output_clk_determine_rate() division by zero is possible if the
> following conditions are met:
> - rate > (parent_rate / 2);
> - (parent_rate / 2) is not multiple of rate;
> - CLK_SET_RATE_PARENT flag is not set.
> 
> Add zero value check to prevent division by zero.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 61c34af50c5f ("clk: si5341: Switch to determine_rate")

Nope. The problem was there before this commit.

> Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
> ---
>  drivers/clk/clk-si5341.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c
> index 6e8dd7387cfd..d0d68a5bba74 100644
> --- a/drivers/clk/clk-si5341.c
> +++ b/drivers/clk/clk-si5341.c
> @@ -855,7 +855,7 @@ static int si5341_output_clk_determine_rate(struct clk_hw *hw,
>         } else {
>                 /* We cannot change our parent's rate, report what we can do */
>                 r /= rate;
> -               rate = req->best_parent_rate / (r << 1);
> +               rate = (r << 1) ? req->best_parent_rate / (r << 1) : 0;

This is too ugly. Also, I assume it would be better to provide a higher
rate if the rate request allows it. Returning 0 should basically never
happen.

  reply	other threads:[~2024-09-19 10:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-17  7:52 [PATCH] clk: si5341: Prevent division by zero in si5341_output_clk_determine_rate() Aleksandr Mishin
2024-09-19 10:35 ` Stephen Boyd [this message]
2024-09-19 12:29 ` [PATCH v2] clk: si5341: Adjust rate rounding " Aleksandr Mishin

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=53f1cb2aefeb360002cd840cb8997ae3.sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=amishin@t-argos.ru \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=mike.looijmans@topic.nl \
    --cc=mripard@kernel.org \
    --cc=mturquette@baylibre.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