Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935270AbeAKRTU (ORCPT + 1 other); Thu, 11 Jan 2018 12:19:20 -0500 Received: from mail-eopbgr20057.outbound.protection.outlook.com ([40.107.2.57]:49566 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933942AbeAKRTF (ORCPT ); Thu, 11 Jan 2018 12:19:05 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ed.blake@sondrel.com; Subject: Re: [PATCH] 8250_dw: do not int overflow when rate can not be aplied To: Nuno Goncalves , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org References: <20180111133832.13125-1-nunojpg@gmail.com> From: Ed Blake Message-ID: <57ef28bd-41da-73c2-3004-f9b2ecd8b102@sondrel.com> Date: Thu, 11 Jan 2018 17:18:59 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20180111133832.13125-1-nunojpg@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [195.88.9.101] X-ClientProxiedBy: CWXP265CA0016.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:2e::28) To DB6P191MB0150.EURP191.PROD.OUTLOOK.COM (2603:10a6:4:8d::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5a8c1898-a850-494e-dcba-08d5591768e2 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020069)(4652020)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:DB6P191MB0150; X-Microsoft-Exchange-Diagnostics: 1;DB6P191MB0150;3:Pdd4s6Dxsh8Ray6l4BH8gclBVpkRS79Jw0QQf6kXqRfFM33d0dQKdEy+/D9zU6kvw0UztUA03qk2O4AZ2tCzsqZ18CYJrJc9IWGNCiQ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2xCf48W0bh+UtL2/wt2j/8uPSJgJpoPVWm/5/2SA8HGna9UX9eBjOs+5rfQYOKsslBtbWMb+/vA==;4:d4FW6ibv4TaxxIfRHEu1S7mAkcnsXChR1iB79MkRdefNCX7ngyw70VZeGQxzgXQjX8Dij+ygWnFBPQBKQq6ENiMTRdnRx8CqBoeQLg5bIfPqrDECaleGIYEL4wUAguoDjBgXXKTqS+K+rQtxfSLf4SpHxXrcTOo1ve4tR3xzveontOtH89f8G/PUVatbByhDxTi0cqE5w5gTZ1s+qsF08ASbIz1Rg2gnL+vbnwaBOFZtRA5RXTw0X6DPIY0EBYggEQMMHsz5J+vVnccrBavqmGFC0CyiYA3V35M7Mc0MErS3quzvZp93cQyurzZn+ei6VM2TMd7FliXB1pNsitnOmG75olCVw8o4kewBM/9v3Hk= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85827821059158)(211171220733660); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(3231023)(944501134)(10201501046)(3002001)(93006095)(93001095)(6041268)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123562045)(6072148)(201708071742011);SRVR:DB6P191MB0150;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:DB6P191MB0150; X-Forefront-PRVS: 0549E6FD50 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(396003)(376002)(39380400002)(366004)(39840400004)(346002)(24454002)(199004)(189003)(52146003)(83506002)(106356001)(47776003)(105586002)(52116002)(8676002)(3846002)(68736007)(230700001)(76176011)(316002)(39060400002)(478600001)(8936002)(81166006)(81156014)(31686004)(16576012)(25786009)(23676004)(2486003)(16526018)(66066001)(58126008)(65806001)(65956001)(2906002)(86362001)(575784001)(50466002)(2950100002)(97736004)(59450400001)(36756003)(31696002)(6246003)(77096006)(6486002)(386003)(6116002)(5660300001)(53546011)(64126003)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joX3W3K0DV0FmDx9TnWpb4RispmyD3z5HpnlyUaP8KgnKEFwc95pk/VcMwfnHH48MX3wBbTZVE8+BPfXoSFg0Z/nW7WxhEOUZe86/pbH954/ocu0p55DOB0eyd6EenYcQrE6R6JroLzGSJ4 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: sondrel.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2018 17:19:01.9892 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5a8c1898-a850-494e-dcba-08d5591768e2 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4faa3872-698e-4896-80ec-148b916cb1ba X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6P191MB0150 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: 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 > --- > 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