Skip to contentSkip to conversation

misc: ibmasm: Replace timeval with timespec64

PATCH Superseded Amitoj Kaur Chawla 2 participants 5 messages Oct 23, 2015 Char and misc drivers

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 misc: ibmasm: Replace timeval with timespec64

This patch replaces timeval with timespec64 as 32 bit 'struct timeval' will not give current time beyond 2038.

The patch changes the code to use ktime_get_real_ts64() which returns a 'struct timespec64' instead of do_gettimeofday() which returns a 'struct timeval'

This patch also alters the format strings in sprintf() for now.tv_sec and now.tv_nsec to incorporate 'long long' on 32 bit architectures and leading zeroes respectively.

---
Changes in v2:
-change format string of now.tv_sec to '%llu' -change format string of now.tv_nsec to '%.08lu'

 drivers/misc/ibmasm/ibmasm.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/misc/ibmasm/ibmasm.h +4 -3
index 9b08344..d73be61 100644
@@ -34,6 +34,7 @@
 #include <linux/kref.h>
 #include <linux/device.h>
 #include <linux/input.h>
+#include <linux/time64.h>
 
 /* Driver identification */
 #define DRIVER_NAME	"ibmasm"
@@ -53,9 +54,9 @@ extern int ibmasm_debug;
 
 static inline char *get_timestamp(char *buf)
 {
-	struct timeval now;
-	do_gettimeofday(&now);
-	sprintf(buf, "%lu.%lu", now.tv_sec, now.tv_usec);
+	struct timespec64 now;
+	ktime_get_real_ts64(&now);
+	sprintf(buf, "%llu.%.08lu", (long long)now.tv_sec, now.tv_usec);
 	return buf;
 }
 
Signature · 1 line
1.9.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · On Friday 23 October 2015 17:52:06 Amitoj Kaur Chawla wrote:

This patch replaces timeval with timespec64 as 32 bit 'struct timeval' will not give current time beyond 2038.

The patch changes the code to use ktime_get_real_ts64() which returns a 'struct timespec64' instead of do_gettimeofday() which returns a 'struct timeval'

Quoted 5 lines

This patch also alters the format strings in sprintf() for now.tv_sec and now.tv_nsec to incorporate 'long long' on 32 bit architectures and leading zeroes respectively.

maintainer
#2 lore raw
Quoted 8 lines · On Friday 23 October 2015 15:39:49 Arnd Bergmann wrote:
Quoted 7 lines · On Friday 23 October 2015 17:52:06 Amitoj Kaur Chawla wrote:

This patch replaces timeval with timespec64 as 32 bit 'struct timeval' will not give current time beyond 2038.

The patch changes the code to use ktime_get_real_ts64() which returns a 'struct timespec64' instead of do_gettimeofday() which returns a 'struct timeval'

Quoted 7 lines
Quoted 5 lines

This patch also alters the format strings in sprintf() for now.tv_sec and now.tv_nsec to incorporate 'long long' on 32 bit architectures and leading zeroes respectively.

I was going to suggest to send this to the maintainers now, but after checking the MAINTAINERS file myself, I see that this would be Greg and me ;-)

Greg, can you pick this up into the char-misc tree?

Arnd

#3 lore raw
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · On Friday 23 October 2015 15:39:49 Arnd Bergmann wrote:
Quoted 12 lines · On Friday 23 October 2015 17:52:06 Amitoj Kaur Chawla wrote:

This patch replaces timeval with timespec64 as 32 bit 'struct timeval' will not give current time beyond 2038.

The patch changes the code to use ktime_get_real_ts64() which returns a 'struct timespec64' instead of do_gettimeofday() which returns a 'struct timeval'

This patch also alters the format strings in sprintf() for now.tv_sec and now.tv_nsec to incorporate 'long long' on 32 bit architectures and leading zeroes respectively.

Quoted 8 lines
Quoted 1 line

I was going to suggest to send this to the maintainers now, but after checking the MAINTAINERS file myself, I see that this would be Greg and me ;-)

Greg, can you pick this up into the char-misc tree?

Arnd

Hi Arnd,

I made a slight error while sending v2 which I caught after figuring out of my issue of compiling the module.

I'm sending a v3 after build testing it.

Should I cc you and Greg separately or let it be?

Signature · 1 line
Amitoj
maintainer
#4 lore raw
Quoted 25 lines · On Friday 23 October 2015 19:28:00 Amitoj Kaur Chawla wrote:
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · On Friday 23 October 2015 15:39:49 Arnd Bergmann wrote:
Quoted 12 lines · On Friday 23 October 2015 17:52:06 Amitoj Kaur Chawla wrote:

This patch replaces timeval with timespec64 as 32 bit 'struct timeval' will not give current time beyond 2038.

The patch changes the code to use ktime_get_real_ts64() which returns a 'struct timespec64' instead of do_gettimeofday() which returns a 'struct timeval'

This patch also alters the format strings in sprintf() for now.tv_sec and now.tv_nsec to incorporate 'long long' on 32 bit architectures and leading zeroes respectively.

Quoted 8 lines
Quoted 1 line

I was going to suggest to send this to the maintainers now, but after checking the MAINTAINERS file myself, I see that this would be Greg and me

Greg, can you pick this up into the char-misc tree?

Arnd

Quoted 8 lines

Hi Arnd,

I made a slight error while sending v2 which I caught after figuring out of my issue of compiling the module.

I'm sending a v3 after build testing it.

Should I cc you and Greg separately or let it be?

In general, it helps to Cc maintainers. We are good at ignoring duplicate mails.

Arnd