From patchwork Thu Nov 12 13:45:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deng Chao X-Patchwork-Id: 56432 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp423955lbb; Thu, 12 Nov 2015 05:46:23 -0800 (PST) X-Received: by 10.68.113.194 with SMTP id ja2mr22814452pbb.52.1447335983262; Thu, 12 Nov 2015 05:46:23 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id iu8si20146299pbc.58.2015.11.12.05.46.23; Thu, 12 Nov 2015 05:46: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 S1752776AbbKLNqW (ORCPT + 1 other); Thu, 12 Nov 2015 08:46:22 -0500 Received: from mail-pa0-f48.google.com ([209.85.220.48]:34189 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753296AbbKLNqV (ORCPT ); Thu, 12 Nov 2015 08:46:21 -0500 Received: by padhx2 with SMTP id hx2so65561751pad.1 for ; Thu, 12 Nov 2015 05:46: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=xdyCHQJH9+dkyIqkXNFCqzBuVi1wlY7dpH1hEnwQTuQ=; b=ML4ho+890u+hcn1A7aVu+XEy1q2ifsz/rrXSOsTlzmxZcy2hdpd7OXrlA1BM+zXIxd SC5QlwnlKrFKUl1r1rUXXePpsr8Xsg6PlyvFyg/kp5QhUy2YVxLPfHJZ9ZMDl9LVfVcZ 98mgRFz2e7rsvUZaVYH+rDnbylcz90WNXf5l306wLiC48zqyGxa9eVSAnG3UzZmxXCn8 14xDzYdhuFQiuCtIQHZf/ry5OJSaKp/LyGY/sBoMz6fWNAb0+P9xB8tSm7W0Ns54xS24 tlslfrD7eMTCIrBtf73sXKFGUEAF+5s3RtwEB8M0q336ob59LNRIKhKPyKQlxJwZc7uj Cw0A== 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=xdyCHQJH9+dkyIqkXNFCqzBuVi1wlY7dpH1hEnwQTuQ=; b=UE9Pu9ZiATWwNO55n3q2HcL/s85fVGQrlHirofSS4b+csSerZSXb0uKw1nDw3SRmBh tPswQG/0Zz6iQtknYVE0w9ePDNqRqH6oa0wWtWnUzUT8vriGhwZBuZjMWsTjz0Tc1FrM 9CRZmMom1EN+H8BF3ubuy4QOX1xgH2aN+utwF/OIuekL+3BmF1BqnT/U6NLXN9A9auox Blbfr7791tN1Cp7s63H67zayyf1FAOe9EfLjTnO+wQeJNuBWnkY/GY4g+w7U2/DkcM/P LEut1jU2/PZO1i0LGAr0oG55mel/48Z9AD5TMGzkjNhrk+N0Fqc630Xlo38C3/fJksZp oQjg== X-Gm-Message-State: ALoCoQmNw1ijYNR79WWKvzhchgOpkdaSFJvYzloXhmRA/eBcPCMWOrBoCtENHS/L0yTM6qVx7jMz X-Received: by 10.66.55.105 with SMTP id r9mr23179185pap.137.1447335980640; Thu, 12 Nov 2015 05:46:20 -0800 (PST) Received: from localhost.localdomain ([167.160.116.42]) by smtp.gmail.com with ESMTPSA id sn9sm15008129pac.16.2015.11.12.05.46.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Nov 2015 05:46:20 -0800 (PST) From: DengChao To: sonic.zhang@analog.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: y2038@lists.linaro.org, chao.deng@linaro.org Subject: [PATCH V1] serial:bfin-uart:Remove 'struct timeval' Date: Thu, 12 Nov 2015 21:45:47 +0800 Message-Id: <1447335947-14877-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(). 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;