Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934286AbeAKMry (ORCPT + 1 other); Thu, 11 Jan 2018 07:47:54 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:44920 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932531AbeAKMrw (ORCPT ); Thu, 11 Jan 2018 07:47:52 -0500 X-Google-Smtp-Source: ACJfBoslXlKhmldKLTzZSug73RD/tuHEXlKnUioUjWtG8smK9++QSeP2v9qtAMcqYLsrhapafIYcPtpqX9feMovEMm0= MIME-Version: 1.0 From: =?UTF-8?Q?Nuno_Gon=C3=A7alves?= Date: Thu, 11 Jan 2018 13:47:31 +0100 Message-ID: Subject: 8250_dw bug To: ed.blake@sondrel.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Dear Ed and Greg, There is a small bug on de9e33bdfa22e607a88494ff21e9196d00bf4550, at least on 32bit devices. Line 274 if (rate >= i * min_rate && rate <= i * max_rate) This will overflow when min_rate/max_rate is large and can not be achieved in the hardware. Eg. stty -F /dev/ttyS2 raw 3500000 (not achievable on my board). target_rate=56000000 (for 3500000baud) min_rate=55125000 max_rate=56875000 rate=24000000 (clk_round_rate for my board) Since my board can only do 1500000baud, this loop will keep incrementing i until i=77*56875000 will overflow, and there are unexpected results. I suggest this patch: --- 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; + break; + } + + if (rate <= i * max_rate) break; } if (i <= UART_DIV_MAX) { Let me know if you want me to submit the formal patch. Thanks, Nuno