Skip to contentSkip to conversation

firewire: Replace timeval with timespec64

PATCH Superseded Amitoj Kaur Chawla 2 participants 5 messages Oct 21, 2015 – Oct 22, 2015 Firewire

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firewire: Replace timeval with timespec64

32 bit systems using 'struct timeval' will break in the year 2038, so we replace the code appropriately.

This patch replaces timeval with timespec64.

---
 drivers/firewire/nosy.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/firewire/nosy.c +6 -4
index 76b2d39..42c38dd 100644
@@ -33,6 +33,7 @@
 #include <linux/sched.h> /* required for linux/wait.h */
 #include <linux/slab.h>
 #include <linux/spinlock.h>
+#include <linux/time64.h>
 #include <linux/timex.h>
 #include <linux/uaccess.h>
 #include <linux/wait.h>
@@ -413,17 +414,18 @@ static void
 packet_irq_handler(struct pcilynx *lynx)
 {
 	struct client *client;
-	u32 tcode_mask, tcode;
+	u32 tcode_mask, tcode, tv_usec;
 	size_t length;
-	struct timeval tv;
+	struct timespec ts64;
 
 	/* FIXME: Also report rcv_speed. */
 
 	length = __le32_to_cpu(lynx->rcv_pcl->pcl_status) & 0x00001fff;
 	tcode  = __le32_to_cpu(lynx->rcv_buffer[1]) >> 4 & 0xf;
 
-	do_gettimeofday(&tv);
-	lynx->rcv_buffer[0] = (__force __le32)tv.tv_usec;
+	getnstimeofday64(&ts64);
+	tv_usec = ts64.tv_nsec / NSEC_PER_USEC;
+	lynx->rcv_buffer[0] = (__force __le32)tv_usec;
 
 	if (length == PHY_PACKET_SIZE)
 		tcode_mask = 1 << TCODE_PHY_PACKET;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 6 lines · On Thursday 22 October 2015 03:05:44 Amitoj Kaur Chawla wrote:

32 bit systems using 'struct timeval' will break in the year 2038, so we replace the code appropriately.

This patch replaces timeval with timespec64.

The patch looks correct to me, nice work.

A few small points:

- It would help to be clearer about the fact that this driver is not broken in 2038, because we only use the microsecond portion of the current time.

drivers/firewire/nosy.c static void · line 417

Quoted 6 lines
drivers/firewire/nosy.c +1 -1
@@ -413,17 +414,18 @@ static void
 packet_irq_handler(struct pcilynx *lynx)
 {
        struct client *client;
-       u32 tcode_mask, tcode;
+       u32 tcode_mask, tcode, tv_usec;

The naming of the new local variable doesn't make sense in the absence of struct timeval. Either rename it to something like 'timestamp' or remove the variable and do the /NSEC_PER_USEC computation in place.

drivers/firewire/nosy.c static void · line 428

Quoted 5 lines
drivers/firewire/nosy.c +3 -2
-       do_gettimeofday(&tv);
-       lynx->rcv_buffer[0] = (__force __le32)tv.tv_usec;
+       getnstimeofday64(&ts64);
+       tv_usec = ts64.tv_nsec / NSEC_PER_USEC;
+       lynx->rcv_buffer[0] = (__force __le32)tv_usec;

I have a small preference for ktime_get_real_ts64() over getnstimeofday64(), though the two are functionally identical.

When you have addressed these, please send the patch again, and Cc the maintainers according to scripts/get_maintainer.pl.

Arnd

#2 lore raw
Quoted 34 lines · Arnd Bergmann
Quoted 6 lines · On Thursday 22 October 2015 03:05:44 Amitoj Kaur Chawla wrote:

32 bit systems using 'struct timeval' will break in the year 2038, so we replace the code appropriately.

This patch replaces timeval with timespec64.

The patch looks correct to me, nice work.

A few small points:

- It would help to be clearer about the fact that this driver is not broken in 2038, because we only use the microsecond portion of the current time.

drivers/firewire/nosy.c static void · line 417

Quoted 6 lines
drivers/firewire/nosy.c +1 -1
@@ -413,17 +414,18 @@ static void
 packet_irq_handler(struct pcilynx *lynx)
 {
        struct client *client;
-       u32 tcode_mask, tcode;
+       u32 tcode_mask, tcode, tv_usec;

The naming of the new local variable doesn't make sense in the absence of struct timeval. Either rename it to something like 'timestamp' or remove the variable and do the /NSEC_PER_USEC computation in place.

drivers/firewire/nosy.c static void · line 428

Quoted 5 lines
drivers/firewire/nosy.c +3 -2
-       do_gettimeofday(&tv);
-       lynx->rcv_buffer[0] = (__force __le32)tv.tv_usec;
+       getnstimeofday64(&ts64);
+       tv_usec = ts64.tv_nsec / NSEC_PER_USEC;
+       lynx->rcv_buffer[0] = (__force __le32)tv_usec;
Quoted 5 lines

I have a small preference for ktime_get_real_ts64() over getnstimeofday64(), though the two are functionally identical.

When you have addressed these, please send the patch again, and Cc the maintainers according to scripts/get_maintainer.pl.

Okay. I'll do all of this. One question, I've replaced timeval with timespec. It should be timespec64 right? I caught it after sending the patch.

Signature · 1 line
Amitoj
#3 lore raw
Quoted 9 lines · On Thursday 22 October 2015 03:26:22 Amitoj Kaur Chawla wrote:
Quoted 9 lines

drivers/firewire/nosy.c static void · line 428

Quoted 5 lines
drivers/firewire/nosy.c +3 -2
-       do_gettimeofday(&tv);
-       lynx->rcv_buffer[0] = (__force __le32)tv.tv_usec;
+       getnstimeofday64(&ts64);
+       tv_usec = ts64.tv_nsec / NSEC_PER_USEC;
+       lynx->rcv_buffer[0] = (__force __le32)tv_usec;

I have a small preference for ktime_get_real_ts64() over getnstimeofday64(), though the two are functionally identical.

Quoted 6 lines
Quoted 2 lines

When you have addressed these, please send the patch again, and Cc the maintainers according to scripts/get_maintainer.pl.

Okay. I'll do all of this. One question, I've replaced timeval with timespec. It should be timespec64 right? I caught it after sending the patch.

Ah, I did not see that. Yes, that would have been the right choice. More importantly, you should not have sent out the patch until it was compile-tested. The tutorial should have information about how to do that, if you can't figure it out, ask for more information on IRC or here.

Arnd

#4 lore raw
Quoted 17 lines · Arnd Bergmann
Quoted 9 lines · On Thursday 22 October 2015 03:26:22 Amitoj Kaur Chawla wrote:
Quoted 9 lines

drivers/firewire/nosy.c static void · line 428

Quoted 5 lines
drivers/firewire/nosy.c +3 -2
-       do_gettimeofday(&tv);
-       lynx->rcv_buffer[0] = (__force __le32)tv.tv_usec;
+       getnstimeofday64(&ts64);
+       tv_usec = ts64.tv_nsec / NSEC_PER_USEC;
+       lynx->rcv_buffer[0] = (__force __le32)tv_usec;

I have a small preference for ktime_get_real_ts64() over getnstimeofday64(), though the two are functionally identical.

Quoted 6 lines
Quoted 2 lines

When you have addressed these, please send the patch again, and Cc the maintainers according to scripts/get_maintainer.pl.

Okay. I'll do all of this. One question, I've replaced timeval with timespec. It should be timespec64 right? I caught it after sending the patch.

Quoted 7 lines

Ah, I did not see that. Yes, that would have been the right choice. More importantly, you should not have sent out the patch until it was compile-tested. The tutorial should have information about how to do that, if you can't figure it out, ask for more information on IRC or here.

Arnd

Okay, will see the tutorial!

Thanks,

Signature · 1 line
Amitoj