All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] prism54: isl_38xx: Replace 'struct timeval'
@ 2016-03-22  9:55 ` Tina Ruchandani
  0 siblings, 0 replies; 4+ messages in thread
From: Tina Ruchandani @ 2016-03-22  9:55 UTC (permalink / raw)
  To: y2038; +Cc: linux-wireless, netdev, arnd, linux-kernel, Kalle Valo

'struct timeval' uses a 32-bit seconds field which will overflow in
year 2038 and beyond. This patch is part of a larger effort to remove
all instances of 'struct timeval' from the kernel and replace them
with 64-bit timekeeping variables.
The correctness of the code isn't affected by this patch - the seconds
value being printed would earlier be wrong due to overflow in timeval,
and now it gets truncated to 32-bit due to the 'long' cast used on
tv.sec field to prevent compiler warnings. Truly fixing this would 
require changing the debug print to print more than 8 digits and using 
a different specifier from %li.
The patch was build-tested / debugged by removing the
"if VERBOSE > SHOW_ERROR_MESSAGES" guards.

Signed-off-by: Tina Ruchandani <ruchandani.tina@gmail.com>
---
 drivers/net/wireless/intersil/prism54/isl_38xx.c | 29 +++++++++++++++---------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/intersil/prism54/isl_38xx.c b/drivers/net/wireless/intersil/prism54/isl_38xx.c
index 333c1a2..e510375 100644
--- a/drivers/net/wireless/intersil/prism54/isl_38xx.c
+++ b/drivers/net/wireless/intersil/prism54/isl_38xx.c
@@ -19,6 +19,7 @@
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/delay.h>
+#include <linux/ktime.h>

 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -113,7 +114,7 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)

 #if VERBOSE > SHOW_ERROR_MESSAGES
 	u32 counter = 0;
-	struct timeval current_time;
+	struct timespec64 current_ts64;
 	DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
 #endif

@@ -121,22 +122,25 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)
 	if (asleep) {
 		/* device is in powersave, trigger the device for wakeup */
 #if VERBOSE > SHOW_ERROR_MESSAGES
-		do_gettimeofday(&current_time);
+		ktime_get_real_ts64(&current_ts64);
 		DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n",
-		      current_time.tv_sec, (long)current_time.tv_usec);
+		      (long)current_ts64.tv_sec,
+		      (long)(current_ts64.tv_nsec / NSEC_PER_USEC));

 		DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
-		      current_time.tv_sec, (long)current_time.tv_usec,
+		      (long)current_ts64.tv_sec,
+		      (long)(current_ts64.tv_nsec / NSEC_PER_USEC),
 		      readl(device_base + ISL38XX_CTRL_STAT_REG));
 #endif

 		reg = readl(device_base + ISL38XX_INT_IDENT_REG);
 		if (reg == 0xabadface) {
 #if VERBOSE > SHOW_ERROR_MESSAGES
-			do_gettimeofday(&current_time);
+			ktime_get_real_ts64(&current_ts64);
 			DEBUG(SHOW_TRACING,
 			      "%08li.%08li Device register abadface\n",
-			      current_time.tv_sec, (long)current_time.tv_usec);
+			      (long)current_ts64.tv_sec,
+			      (long)(current_ts64.tv_nsec / NSEC_PER_USEC));
 #endif
 			/* read the Device Status Register until Sleepmode bit is set */
 			while (reg = readl(device_base + ISL38XX_CTRL_STAT_REG),
@@ -150,12 +154,14 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)
 #if VERBOSE > SHOW_ERROR_MESSAGES
 			DEBUG(SHOW_TRACING,
 			      "%08li.%08li Device register read %08x\n",
-			      current_time.tv_sec, (long)current_time.tv_usec,
+			      (long)current_ts64.tv_sec,
+			      (long)(current_ts64.tv_nsec / NSEC_PER_USEC),
 			      readl(device_base + ISL38XX_CTRL_STAT_REG));
-			do_gettimeofday(&current_time);
+			ktime_get_real_ts64(&current_ts64);
 			DEBUG(SHOW_TRACING,
 			      "%08li.%08li Device asleep counter %i\n",
-			      current_time.tv_sec, (long)current_time.tv_usec,
+			      (long)current_ts64.tv_sec,
+			      (long)(current_ts64.tv_nsec / NSEC_PER_USEC),
 			      counter);
 #endif
 		}
@@ -168,9 +174,10 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)

 		/* perform another read on the Device Status Register */
 		reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
-		do_gettimeofday(&current_time);
+		ktime_get_real_ts64(&current_ts64);
 		DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
-		      current_time.tv_sec, (long)current_time.tv_usec, reg);
+		      (long)current_ts64.tv_sec,
+		      (long)(current_ts64.tv_nsec / NSEC_PER_USEC), reg);
 #endif
 	} else {
 		/* device is (still) awake  */
--
2.8.0.rc3.226.g39d4020


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

* [PATCH] prism54: isl_38xx: Replace 'struct timeval'
@ 2016-03-22  9:55 ` Tina Ruchandani
  0 siblings, 0 replies; 4+ messages in thread
From: Tina Ruchandani @ 2016-03-22  9:55 UTC (permalink / raw)
  To: y2038-cunTk1MwBs8s++Sfvej+rw
  Cc: linux-wireless-u79uwXL29TY76Z2rM5mHXA,
	netdev-u79uwXL29TY76Z2rM5mHXA, arnd-r2nGTMty4D4,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Kalle Valo

'struct timeval' uses a 32-bit seconds field which will overflow in
year 2038 and beyond. This patch is part of a larger effort to remove
all instances of 'struct timeval' from the kernel and replace them
with 64-bit timekeeping variables.
The correctness of the code isn't affected by this patch - the seconds
value being printed would earlier be wrong due to overflow in timeval,
and now it gets truncated to 32-bit due to the 'long' cast used on
tv.sec field to prevent compiler warnings. Truly fixing this would 
require changing the debug print to print more than 8 digits and using 
a different specifier from %li.
The patch was build-tested / debugged by removing the
"if VERBOSE > SHOW_ERROR_MESSAGES" guards.

Signed-off-by: Tina Ruchandani <ruchandani.tina-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/net/wireless/intersil/prism54/isl_38xx.c | 29 +++++++++++++++---------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/intersil/prism54/isl_38xx.c b/drivers/net/wireless/intersil/prism54/isl_38xx.c
index 333c1a2..e510375 100644
--- a/drivers/net/wireless/intersil/prism54/isl_38xx.c
+++ b/drivers/net/wireless/intersil/prism54/isl_38xx.c
@@ -19,6 +19,7 @@
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/delay.h>
+#include <linux/ktime.h>

 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -113,7 +114,7 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)

 #if VERBOSE > SHOW_ERROR_MESSAGES
 	u32 counter = 0;
-	struct timeval current_time;
+	struct timespec64 current_ts64;
 	DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
 #endif

@@ -121,22 +122,25 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)
 	if (asleep) {
 		/* device is in powersave, trigger the device for wakeup */
 #if VERBOSE > SHOW_ERROR_MESSAGES
-		do_gettimeofday(&current_time);
+		ktime_get_real_ts64(&current_ts64);
 		DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n",
-		      current_time.tv_sec, (long)current_time.tv_usec);
+		      (long)current_ts64.tv_sec,
+		      (long)(current_ts64.tv_nsec / NSEC_PER_USEC));

 		DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
-		      current_time.tv_sec, (long)current_time.tv_usec,
+		      (long)current_ts64.tv_sec,
+		      (long)(current_ts64.tv_nsec / NSEC_PER_USEC),
 		      readl(device_base + ISL38XX_CTRL_STAT_REG));
 #endif

 		reg = readl(device_base + ISL38XX_INT_IDENT_REG);
 		if (reg == 0xabadface) {
 #if VERBOSE > SHOW_ERROR_MESSAGES
-			do_gettimeofday(&current_time);
+			ktime_get_real_ts64(&current_ts64);
 			DEBUG(SHOW_TRACING,
 			      "%08li.%08li Device register abadface\n",
-			      current_time.tv_sec, (long)current_time.tv_usec);
+			      (long)current_ts64.tv_sec,
+			      (long)(current_ts64.tv_nsec / NSEC_PER_USEC));
 #endif
 			/* read the Device Status Register until Sleepmode bit is set */
 			while (reg = readl(device_base + ISL38XX_CTRL_STAT_REG),
@@ -150,12 +154,14 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)
 #if VERBOSE > SHOW_ERROR_MESSAGES
 			DEBUG(SHOW_TRACING,
 			      "%08li.%08li Device register read %08x\n",
-			      current_time.tv_sec, (long)current_time.tv_usec,
+			      (long)current_ts64.tv_sec,
+			      (long)(current_ts64.tv_nsec / NSEC_PER_USEC),
 			      readl(device_base + ISL38XX_CTRL_STAT_REG));
-			do_gettimeofday(&current_time);
+			ktime_get_real_ts64(&current_ts64);
 			DEBUG(SHOW_TRACING,
 			      "%08li.%08li Device asleep counter %i\n",
-			      current_time.tv_sec, (long)current_time.tv_usec,
+			      (long)current_ts64.tv_sec,
+			      (long)(current_ts64.tv_nsec / NSEC_PER_USEC),
 			      counter);
 #endif
 		}
@@ -168,9 +174,10 @@ isl38xx_trigger_device(int asleep, void __iomem *device_base)

 		/* perform another read on the Device Status Register */
 		reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
-		do_gettimeofday(&current_time);
+		ktime_get_real_ts64(&current_ts64);
 		DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
-		      current_time.tv_sec, (long)current_time.tv_usec, reg);
+		      (long)current_ts64.tv_sec,
+		      (long)(current_ts64.tv_nsec / NSEC_PER_USEC), reg);
 #endif
 	} else {
 		/* device is (still) awake  */
--
2.8.0.rc3.226.g39d4020

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [Y2038] [PATCH] prism54: isl_38xx: Replace 'struct timeval'
  2016-03-22  9:55 ` Tina Ruchandani
@ 2016-03-22 11:51   ` Arnd Bergmann
  -1 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2016-03-22 11:51 UTC (permalink / raw)
  To: y2038; +Cc: Tina Ruchandani, Kalle Valo, netdev, linux-wireless, linux-kernel

On Tuesday 22 March 2016 02:55:22 Tina Ruchandani wrote:
> Truly fixing this would 
> require changing the debug print to print more than 8 digits and using 
> a different specifier from %li.

Why not just change it to %lli, and a cast to s64? I don't think the
format string or the number of digits is important here because it's just
debug output that is normally disabled.

I also see an existing bug in the format string: "%08li.%08li" means we
end up printing a six digit microsecond value with two leading zeros,
which is rather confusing. I think using "%lld.%06ld" would be best
here, or possibly "%lld.%09ld" to print the whole nanoseconds so we
can skip the division.

	Arnd

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

* Re: [Y2038] [PATCH] prism54: isl_38xx: Replace 'struct timeval'
@ 2016-03-22 11:51   ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2016-03-22 11:51 UTC (permalink / raw)
  To: y2038-cunTk1MwBs8s++Sfvej+rw
  Cc: Tina Ruchandani, Kalle Valo, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-wireless-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Tuesday 22 March 2016 02:55:22 Tina Ruchandani wrote:
> Truly fixing this would 
> require changing the debug print to print more than 8 digits and using 
> a different specifier from %li.

Why not just change it to %lli, and a cast to s64? I don't think the
format string or the number of digits is important here because it's just
debug output that is normally disabled.

I also see an existing bug in the format string: "%08li.%08li" means we
end up printing a six digit microsecond value with two leading zeros,
which is rather confusing. I think using "%lld.%06ld" would be best
here, or possibly "%lld.%09ld" to print the whole nanoseconds so we
can skip the division.

	Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2016-03-22 11:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-22  9:55 [PATCH] prism54: isl_38xx: Replace 'struct timeval' Tina Ruchandani
2016-03-22  9:55 ` Tina Ruchandani
2016-03-22 11:51 ` [Y2038] " Arnd Bergmann
2016-03-22 11:51   ` 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.