[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAD=FV=UF3x5RHrQH-m1X-4kQSsKiufLnkew=VuJz7W9EAi3GHQ@mail.gmail.com>
Date: Tue, 31 May 2022 12:28:16 -0700
From: Doug Anderson <dianders@...omium.org>
To: Vijaya Krishna Nivarthi <quic_vnivarth@...cinc.com>
Cc: Andy Gross <agross@...nel.org>,
Bjorn Andersson <bjorn.andersson@...aro.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jiri Slaby <jirislaby@...nel.org>,
linux-arm-msm <linux-arm-msm@...r.kernel.org>,
linux-serial@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>,
quic_msavaliy@...cinc.com, Matthias Kaehlcke <mka@...omium.org>,
Stephen Boyd <swboyd@...omium.org>
Subject: Re: [PATCH] tty: serial: qcom-geni-serial: minor fixes to get_clk_div_rate()
Hi,
On Tue, May 31, 2022 at 11:18 AM Vijaya Krishna Nivarthi
<quic_vnivarth@...cinc.com> wrote:
>
> Add missing initialisation and correct type casting
>
> Signed-off-by: Vijaya Krishna Nivarthi <quic_vnivarth@...cinc.com>
> ---
> drivers/tty/serial/qcom_geni_serial.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
> index 4733a23..08f3ad4 100644
> --- a/drivers/tty/serial/qcom_geni_serial.c
> +++ b/drivers/tty/serial/qcom_geni_serial.c
> @@ -943,11 +943,11 @@ static int qcom_geni_serial_startup(struct uart_port *uport)
> static unsigned long get_clk_div_rate(struct clk *clk, unsigned int baud,
> unsigned int sampling_rate, unsigned int *clk_div)
> {
> - unsigned long ser_clk;
> + unsigned long ser_clk = 0;
In this patch it's not at all obvious why you'd need to init to 0. I
think the "for loop" is guaranteed to run at least once because
"max_div" is known at compile time. ...and currently each time through
the "for" loop you'll always set "ser_clk".
I think in a future patch you'll want to _remove_ this from the for loop:
if (!prev)
ser_clk = freq;
...and _that's_ when you should init "ser_clk" to 0. Until then I'd
leave it as uninitialized...
Honestly, I'd throw all the fixes into one series, too.
> unsigned long desired_clk;
> unsigned long freq, prev;
> unsigned long div, maxdiv;
> - int64_t mult;
> + unsigned long long mult;
>
> desired_clk = baud * sampling_rate;
> if (!desired_clk) {
> @@ -959,8 +959,8 @@ static unsigned long get_clk_div_rate(struct clk *clk, unsigned int baud,
> prev = 0;
>
> for (div = 1; div <= maxdiv; div++) {
> - mult = div * desired_clk;
> - if (mult > ULONG_MAX)
> + mult = (unsigned long long)div * (unsigned long long)desired_clk;
I think you only need to cast one of the two. The other will be
up-cast automatically.
> + if (mult > (unsigned long long)ULONG_MAX)
I don't think you need this cast. As far as I know the C language will
"upcast" to the larger of the two types.
-Doug
Powered by blists - more mailing lists