All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V1] serial:bfin-uart:Remove 'struct timeval'
@ 2015-11-12 13:45 ` DengChao
  0 siblings, 0 replies; 3+ messages in thread
From: DengChao @ 2015-11-12 13:45 UTC (permalink / raw)
  To: sonic.zhang, linux-serial, linux-kernel; +Cc: y2038, chao.deng

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 <chao.deng@linaro.org>
---
 drivers/tty/serial/bfin_uart.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

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;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH V1] serial:bfin-uart:Remove 'struct timeval'
@ 2015-11-12 13:45 ` DengChao
  0 siblings, 0 replies; 3+ messages in thread
From: DengChao @ 2015-11-12 13:45 UTC (permalink / raw)
  To: sonic.zhang, linux-serial, linux-kernel; +Cc: y2038, chao.deng

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 <chao.deng@linaro.org>
---
 drivers/tty/serial/bfin_uart.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

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;
-- 
1.9.1

_______________________________________________
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Y2038] [PATCH V1] serial:bfin-uart:Remove 'struct timeval'
  2015-11-12 13:45 ` DengChao
  (?)
@ 2015-11-12 13:49 ` Arnd Bergmann
  -1 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2015-11-12 13:49 UTC (permalink / raw)
  To: y2038; +Cc: DengChao, sonic.zhang, linux-serial, linux-kernel

On Thursday 12 November 2015 21:45:47 DengChao wrote:
> 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 <chao.deng@linaro.org>
> 

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-12 13:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-12 13:45 [PATCH V1] serial:bfin-uart:Remove 'struct timeval' DengChao
2015-11-12 13:45 ` DengChao
2015-11-12 13:49 ` [Y2038] " Arnd Bergmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.