From patchwork Sun Dec 13 10:14:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deng Chao X-Patchwork-Id: 58320 Delivered-To: patch@linaro.org Received: by 10.112.73.68 with SMTP id j4csp865701lbv; Sun, 13 Dec 2015 02:15:23 -0800 (PST) X-Received: by 10.66.155.197 with SMTP id vy5mr37705237pab.109.1450001723491; Sun, 13 Dec 2015 02:15:23 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wz5si10865984pab.68.2015.12.13.02.15.23; Sun, 13 Dec 2015 02:15:23 -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; 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; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751541AbbLMKPW (ORCPT + 1 other); Sun, 13 Dec 2015 05:15:22 -0500 Received: from mail-pf0-f177.google.com ([209.85.192.177]:33455 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751496AbbLMKPV (ORCPT ); Sun, 13 Dec 2015 05:15:21 -0500 Received: by pfnn128 with SMTP id n128so89886657pfn.0 for ; Sun, 13 Dec 2015 02:15:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=VDXe/e5MduLofcVmRLV3B+4DTDNPjvlkilUv/NOVBBI=; b=Mc1V7uhNRbk+neNOqLpf6TWVHyHju3LO1ia/HvBgAkQVLOdKQxxzBytrH0QbEiOr4f 75UrLUZCIHqTKUUCyE+dY1WUl/waTqmYwJMXJd08A/97k8nefD2V/FFyLYrE52m7vOQO gRZ2eV0Ta5dq8rnkfpseq4bgZmYBRxaR//W2OpwrTVUIdJUMMzJSYTEZdu6YmtjvpE10 EJeJbNyrIWLMLMHqKjTcJ2NNSIv9rjweOCn1tM/9Qig6pGftzpPhUcfWzD7dRFhRaEg4 KDTD3V8+/GNwjYCFw68KgQWRJDrjgJJ/4vtLIjnrMfMsiOkcNKi6IWZECYJ0kWE52mkH sZMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VDXe/e5MduLofcVmRLV3B+4DTDNPjvlkilUv/NOVBBI=; b=UUqZL/Wo8J8J0/H8TLitcQ3iYUy66GgO41RLzs3uZYEEJaVFZ09Dazf5CD3Jgh1T33 nyBT5QUw57ZB7RZkhMjZNKaFoc4XLzrHKlcOOyzTizJoWGZi2wdSsVj40QtPycDBQoRG RrtMm+AZYyv6VQv+NOCILcH6VcYBCi9zdC0OsDgwuXHm+v5N7yOBnLP9KQR2MFcJk9F6 g2nBNDpHDuHxpXDPFHGcKn45BOeNnX169fVARszVPrkPumwju4WpNczItLnFzFRejag+ FoDZLsFk3V9y4ASpCyiqknZ+KPRTxtyqtp0cHAII/F0zbtczZvrmVX/ZVZNoQjCPfaEz wm1Q== X-Gm-Message-State: ALoCoQkRdJ58fHSC7Ykqt38sZAw9l7SSyqiGIsftwL4RS5m708kcdz+8n+fuMFxPMLws5xIEtyQEyidLbJx6Q041TivsFpsC7g== X-Received: by 10.98.14.15 with SMTP id w15mr28084140pfi.145.1450001720891; Sun, 13 Dec 2015 02:15:20 -0800 (PST) Received: from localhost.localdomain ([167.160.116.38]) by smtp.gmail.com with ESMTPSA id by2sm35991486pab.20.2015.12.13.02.15.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 13 Dec 2015 02:15:19 -0800 (PST) From: DengChao To: sonic.zhang@analog.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: chao.deng@linaro.org Subject: [PATCH] serial:bfin-uart:Remove 'struct timeval' Date: Sun, 13 Dec 2015 18:14:57 +0800 Message-Id: <1450001697-5015-1-git-send-email-chao.deng@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org The bfin-uart code uses real time with struct timeval. This will cause problems on 32-bit architectures in 2038 when time_t overflows. Since the code just needs delta value of time, it is not necessary to record them in real time. This patch changes the code to use the monotonic time instead, replaces struct timeval and do_gettimeofday() with u64 and ktime_get_ns(). Reviewed-by: Arnd Bergmann Signed-off-by: DengChao --- drivers/tty/serial/bfin_uart.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) -- 1.9.1 -- 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/bfin_uart.c b/drivers/tty/serial/bfin_uart.c index ae3cf94..1270cc4 100644 --- a/drivers/tty/serial/bfin_uart.c +++ b/drivers/tty/serial/bfin_uart.c @@ -213,7 +213,7 @@ static void bfin_serial_stop_rx(struct uart_port *port) static void bfin_serial_rx_chars(struct bfin_serial_port *uart) { unsigned int status, ch, flg; - static struct timeval anomaly_start = { .tv_sec = 0 }; + static u64 anomaly_start; status = UART_GET_LSR(uart); UART_CLEAR_LSR(uart); @@ -246,27 +246,24 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart) * character time +/- some percent. So 1.5 sounds good. All other * Blackfin families operate properly. Woo. */ - if (anomaly_start.tv_sec) { - struct timeval curr; - suseconds_t usecs; + if (anomaly_start > 0) { + u64 curr, nsecs, threshold_ns; if ((~ch & (~ch + 1)) & 0xff) goto known_good_char; - do_gettimeofday(&curr); - if (curr.tv_sec - anomaly_start.tv_sec > 1) + curr = ktime_get_ns(); + nsecs = curr - anomaly_start; + if (nsecs >> 32) goto known_good_char; - - usecs = 0; - if (curr.tv_sec != anomaly_start.tv_sec) - usecs += USEC_PER_SEC; - usecs += curr.tv_usec - anomaly_start.tv_usec; - - if (usecs > UART_GET_ANOMALY_THRESHOLD(uart)) + + threshold_ns = UART_GET_ANOMALY_THRESHOLD(uart) + * NSEC_PER_USEC; + if (nsecs > threshold_ns) goto known_good_char; if (ch) - anomaly_start.tv_sec = 0; + anomaly_start = 0; else anomaly_start = curr; @@ -274,14 +271,14 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart) known_good_char: status &= ~BI; - anomaly_start.tv_sec = 0; + anomaly_start = 0; } } if (status & BI) { if (ANOMALY_05000363) if (bfin_revid() < 5) - do_gettimeofday(&anomaly_start); + anomaly_start = ktime_get_ns(); uart->port.icount.brk++; if (uart_handle_break(&uart->port)) goto ignore_char;