From patchwork Thu Jan 11 13:38:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Nuno_Gon=C3=A7alves?= X-Patchwork-Id: 124203 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp693203qgn; Thu, 11 Jan 2018 05:39:37 -0800 (PST) X-Google-Smtp-Source: ACJfBoupWpT/sCNSHJp1JjFtYtRzLiMZ/BzoveD15Zub21hKJCsKqQZpPZzsKkFwyfvbfBiCicaU X-Received: by 10.99.94.193 with SMTP id s184mr17887806pgb.311.1515677977721; Thu, 11 Jan 2018 05:39:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515677977; cv=none; d=google.com; s=arc-20160816; b=fGUq8GUViOGdXceraZdYxT+VeZ01Gi8X7wDsQnS1y/vtHnsStXx7VhWfhyGdP7kkx5 UDiC86yO/9JpkDoKr/SBB02Y6qVWY4aEWHDUnrj6wF9vexi/rviMToZF481m+JSLU0l/ u126Aca2CTDRryJExc5vUbVTuxKXCzFyRw5MuqvopDnNtpYb1oh/iVE/7pL7Cn4VpQ7M flw31TLG5umguvxAU59trh6fZXJXlq6W/JoypYMqU/a3RqMXzrUVg5ork1RxGva7Hy5L XwEeELBtGmuVLUmZIHHV3DiVTmviF0vOVc3j1OUBRn/HXMO+pp72+mOnYN/DtDXjmpIP TSdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=lAq6fjoSBc9caQgJUNTN8cMu0VCXt63eyZoEioDpY3w=; b=fcD2ERYHXeTIy1jkOygNzxjk3BLsxk36a+PdOsheeYs0d+Ag62Y+G9DoWaUxGSkFAO 1+W7wioogi4qS2n25nVxL2c+UhwhAc+zOKCoaK5YoH28eqy9/U6Z9RXis9SnhTRAF/KL geHQCgQA9V0VxusLXRRAU4X4Oen2PXPizW8vEw9upygV3iKBpqP/4smLU0ObfXp1w/Z1 l67T9FpIsBaHf7zeBMmWAwbMfMNF5qQVllJ4uKSSa2tBCSBQOQ9oDE8A5Dy+Kvsb0bkX 9h6OiuluC95YuW5bLWq7/8k2qfNWVdcceLnx4xHJFWrM99tdOGqc8YESqvACWVDQ4jnh utzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=q+2fa5Dx; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a33si13834895pla.546.2018.01.11.05.39.37; Thu, 11 Jan 2018 05:39:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=q+2fa5Dx; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752317AbeAKNjg (ORCPT + 2 others); Thu, 11 Jan 2018 08:39:36 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:34847 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751607AbeAKNjf (ORCPT ); Thu, 11 Jan 2018 08:39:35 -0500 Received: by mail-wr0-f196.google.com with SMTP id n9so2211745wrg.2; Thu, 11 Jan 2018 05:39:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=r/yhmT0kmed3T8RXIYpPKP09ZY1jNfc1rrW8GSlJ3eI=; b=q+2fa5Dx9VzZWyEs0pwhVNP3ZjZZGFeGIt+z2EUryMr3bqUqEV4chwVmHYXm4aQF08 Z5msxWiUajhFmY2xwOsULdyVzSmt2VXkAkoQuvwg8pGzScPdaJNmxgSWHTNm3+Pxs5aJ cFwaQ+9pZn73oDiUjQo+RR6El2ziaTDtAswjzg6BSdVXAK9ohJGCAG0pc4FHQqstjYCt /vCBKr7c3n06DyUBttALRWZN5dIAq1N7w2+APHNAyQScyWLG06ZHrcwF85Ks/bYfN6Vi P9vDdHYjTlsT+xUbFubpmn1CsPyqmH9Os5GE/FZIWrOyE3V7oh8aNqZ6KY8iRDnsRGET TPfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=r/yhmT0kmed3T8RXIYpPKP09ZY1jNfc1rrW8GSlJ3eI=; b=NBtqkQI8j/RjanVUygjCbMjmFqF8pMZSsIYyw8Ia4WKNWtByylLeTW0uh2I2Z+EZZf 79TVbzxHj3yd0dw+mnABhV+nAaq0pOXGjcJZBybcKBr+/4xQu7/G1e3c0p+fqIMM7bI6 avPrGxM48Y4GkpNLX/fcVK7tl/nmrXDKnuo41yHq2ITvMnZmzi7cMZcnE2LLShubK8pP +II8mPPjRW42kujYGH0GAt9JNJ3TQCpk4Ctrcak4rF1gb9vr1PaJp22Ud1QlkJAEnOg1 f2dSEZvRzoIyRzNpEF87EI5UNU3ZjwpcxcGR7/cchHe3yxIFn1daQ5deeCl/J5eMj2hP /4mQ== X-Gm-Message-State: AKGB3mLqHaawsXBlxfF57ZCFH6tP2EPqqTQMXJ0AUKb1LCHaJtXO9PeT fken3l8wOApWdgpqKgHCLg0= X-Received: by 10.223.155.131 with SMTP id d3mr19461961wrc.134.1515677974418; Thu, 11 Jan 2018 05:39:34 -0800 (PST) Received: from localhost.localdomain ([2001:a61:413:a600:50fe:6ad:727a:e029]) by smtp.gmail.com with ESMTPSA id g26sm19631440wrb.51.2018.01.11.05.39.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jan 2018 05:39:33 -0800 (PST) From: Nuno Goncalves To: ed.blake@sondrel.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: Nuno Goncalves Subject: [PATCH] 8250_dw: do not int overflow when rate can not be aplied Date: Thu, 11 Jan 2018 14:38:32 +0100 Message-Id: <20180111133832.13125-1-nunojpg@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org 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. 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(-) -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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) {