Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Vijaya Krishna Nivarthi <quic_vnivarth@quicinc.com>
To: Doug Anderson <dianders@chromium.org>
Cc: Andy Gross <agross@kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	linux-arm-msm <linux-arm-msm@vger.kernel.org>,
	<linux-serial@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>, <quic_msavaliy@quicinc.com>,
	Matthias Kaehlcke <mka@chromium.org>,
	"Stephen Boyd" <swboyd@chromium.org>
Subject: Re: [PATCH] tty: serial: qcom-geni-serial: minor fixes to get_clk_div_rate()
Date: Wed, 1 Jun 2022 16:15:59 +0530	[thread overview]
Message-ID: <5d950007-7a92-a41b-e569-79e806adb06a@quicinc.com> (raw)
In-Reply-To: <CAD=FV=UF3x5RHrQH-m1X-4kQSsKiufLnkew=VuJz7W9EAi3GHQ@mail.gmail.com>

Hi,

On 6/1/2022 12:58 AM, Doug Anderson wrote:
> Hi,
>
> On Tue, May 31, 2022 at 11:18 AM Vijaya Krishna Nivarthi
> <quic_vnivarth@quicinc.com> wrote:
>> Add missing initialisation and correct type casting
>>
>> Signed-off-by: Vijaya Krishna Nivarthi <quic_vnivarth@quicinc.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".

Ok, I realised we will never break out of for loop exceeding ULONG_MAX 
in 1st pass, so yes ser_clk will always be set.

> I think in a future patch you'll want to _remove_ this from the for loop:
>
> if (!prev)
>    ser_clk = freq;

Intent is to save (and use) 1st freq if we cannot find an exact divider.

Isn't it ok?

For example please find debug output for a required frequency of 51.2MHz.

We try dividers 1, 2, 3 and end up with 52.1MHz the first result.

[   18.815432] 20220509 get_clk_div_rate desired_clk:51200000
[   18.821081] 20220509 get_clk_div_rate maxdiv:4095
[   18.825924] 20220509 get_clk_div_rate div:1
[   18.830239] 20220509 get_clk_div_rate freq:52174000
[   18.835288] 20220509 get_clk_div_rate div:2
[   18.839628] 20220509 get_clk_div_rate freq:100000000
[   18.844794] 20220509 get_clk_div_rate div:3
[   18.849119] 20220509 get_clk_div_rate freq:100000000
[   18.854254] 20220509 get_clk_div_rate reached max frequency breaking...
[   18.861072] 20220509 get_clk_div_rate clk_div=1, ser_clk=52174000

The behaviour was same earlier too when root_freq table was present.

The table did contain 51.2MHz and we would exit with same but on call to 
clk_set_rate(51.2MHz) we were ending up with 52.1MHz

>
> ...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.

My concern was if there would be a requirement to split the changes.

Will put in all in 1 series with Fixes tag.

>
>
>>          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.
Will change.
>
>
>> +               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.
Will change.
>
>
> -Doug

Thank you.

-Vijay/


  reply	other threads:[~2022-06-01 10:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-31 18:17 [PATCH] tty: serial: qcom-geni-serial: minor fixes to get_clk_div_rate() Vijaya Krishna Nivarthi
2022-05-31 18:28 ` Greg KH
2022-05-31 19:28 ` Doug Anderson
2022-06-01 10:45   ` Vijaya Krishna Nivarthi [this message]
2022-06-01 15:33     ` Doug Anderson
2022-06-03 17:43       ` Vijaya Krishna Nivarthi
2022-06-03 18:40         ` Doug Anderson
2022-06-06 18:19           ` Vijaya Krishna Nivarthi
2022-06-06 19:59             ` Doug Anderson
2022-06-07 17:40               ` Vijaya Krishna Nivarthi
2022-06-07 19:25                 ` Doug Anderson
2022-06-08 18:33                   ` Vijaya Krishna Nivarthi
2022-06-08 22:37                     ` Doug Anderson
2022-06-09 17:48                       ` Vijaya Krishna Nivarthi
2022-06-09 18:08                       ` Vijaya Krishna Nivarthi
2022-06-10  9:33                       ` Vijaya Krishna Nivarthi (Temp) (QUIC)
2022-06-10 17:20                         ` Doug Anderson
2022-06-13 18:16                           ` Vijaya Krishna Nivarthi (Temp) (QUIC)
2022-06-21 17:58                       ` Vijaya Krishna Nivarthi (Temp)
2022-06-23 23:11                         ` Doug Anderson

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=5d950007-7a92-a41b-e569-79e806adb06a@quicinc.com \
    --to=quic_vnivarth@quicinc.com \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mka@chromium.org \
    --cc=quic_msavaliy@quicinc.com \
    --cc=swboyd@chromium.org \
    /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