mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ed Blake <ed.blake@sondrel.com>
To: Nuno Goncalves <nunojpg@gmail.com>,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org
Subject: Re: [PATCH] 8250_dw: do not int overflow when rate can not be aplied
Date: Thu, 11 Jan 2018 17:18:59 +0000	[thread overview]
Message-ID: <57ef28bd-41da-73c2-3004-f9b2ecd8b102@sondrel.com> (raw)
In-Reply-To: <20180111133832.13125-1-nunojpg@gmail.com>

Hi Nuno,

Thanks for reporting this and the patch.

On 11/01/18 13:38, Nuno Goncalves wrote:
> When target_rate is big enough and not permitted in hardware,
> then i is looped to UART_DIV_MAX (0xFFFF), and i * max_rate will overflow
> (32b signed).
>
> A fix is to quit the loop early enough, as soon as rate < i * min_rate as it
> means the rate is not permitted.

'rate < i * min_rate' does not mean the rate is not permitted.  clk_round_rate() gives the nearest achievable rate to the one requested, which may be lower than i * min_rate.  This is not an error and in this case we want to continue the loop searching for an acceptable rate.


>
> This avoids arbitraty rates to be applied. Still in my hardware the max
> allowed rate (1500000) is aplied when a higher is requested. This seems a
> artifact of clk_round_rate which is not understood by me and independent of
> this fix. Might or might not be another bug.
>
> Signed-off-by: Nuno Goncalves <nunojpg@gmail.com>
> ---
>  drivers/tty/serial/8250/8250_dw.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
> index 5bb0c42c88dd..a27ea916abbf 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -267,7 +267,13 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
>  
>  	for (i = 1; i <= UART_DIV_MAX; i++) {
>  		rate = clk_round_rate(d->clk, i * target_rate);
> -		if (rate >= i * min_rate && rate <= i * max_rate)
> +
> +		if (rate < i * min_rate) {
> +			i = UART_DIV_MAX + 1;
> +			break;
> +		}
> +
> +		if (rate <= i * max_rate)
>  			break;
>  	}
>  	if (i <= UART_DIV_MAX) {

-- 
Ed

  reply	other threads:[~2018-01-11 17:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-11 13:38 Nuno Goncalves
2018-01-11 17:18 ` Ed Blake [this message]
2018-01-11 17:28   ` Nuno Gonçalves
2018-01-11 17:48     ` Ed Blake
2018-01-11 17:55       ` Nuno Gonçalves
2018-01-11 18:03         ` Ed Blake
2018-01-12 13:33           ` Ed Blake

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=57ef28bd-41da-73c2-3004-f9b2ecd8b102@sondrel.com \
    --to=ed.blake@sondrel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=nunojpg@gmail.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

all inboxes | Powered by JetHome®