* [PATCH v2] USB: usbmon: Remove timeval usage for timestamp
@ 2015-10-30 5:58 Tina Ruchandani
2015-11-05 16:19 ` Arnd Bergmann
0 siblings, 1 reply; 2+ messages in thread
From: Tina Ruchandani @ 2015-10-30 5:58 UTC (permalink / raw)
To: linux-usb; +Cc: Arnd Bergmann, linux-kernel, y2038, Greg Kroah-Hartman
struct timeval' uses 32-bits for its seconds field and will overflow in
the year 2038 and beyond. This patch replaces the usage of 'struct timeval'
in mon_get_timestamp() with timespec64 which uses a 64-bit seconds field
and is y2038-safe. mon_get_timestamp() truncates the timestamp at 4096 seconds,
so the correctness of the code is not affected. This patch is part of a larger
attempt to remove instances of struct timeval and other 32-bit timekeeping
(time_t, struct timespec) from the kernel.
Signed-off-by: Tina Ruchandani <ruchandani.tina@gmail.com>
Suggested-by: Arnd Bergmann <arnd@arndb.de>
---
Changes in v2:
- Switch to monotonic time since we only care about time elapsed.
---
drivers/usb/mon/mon_text.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index ad40825..98e4f63 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -9,6 +9,7 @@
#include <linux/usb.h>
#include <linux/slab.h>
#include <linux/time.h>
+#include <linux/ktime.h>
#include <linux/export.h>
#include <linux/mutex.h>
#include <linux/debugfs.h>
@@ -176,12 +177,12 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
static inline unsigned int mon_get_timestamp(void)
{
- struct timeval tval;
+ struct timespec64 now;
unsigned int stamp;
- do_gettimeofday(&tval);
- stamp = tval.tv_sec & 0xFFF; /* 2^32 = 4294967296. Limit to 4096s. */
- stamp = stamp * 1000000 + tval.tv_usec;
+ ktime_get_ts64(&now);
+ stamp = now.tv_sec & 0xFFF; /* 2^32 = 4294967296. Limit to 4096s. */
+ stamp = stamp * USEC_PER_SEC + now.tv_nsec / NSEC_PER_USEC;
return stamp;
}
--
2.6.0.rc2.230.g3dd15c0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] USB: usbmon: Remove timeval usage for timestamp
2015-10-30 5:58 [PATCH v2] USB: usbmon: Remove timeval usage for timestamp Tina Ruchandani
@ 2015-11-05 16:19 ` Arnd Bergmann
0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2015-11-05 16:19 UTC (permalink / raw)
To: Tina Ruchandani; +Cc: linux-usb, linux-kernel, y2038, Greg Kroah-Hartman
On Thursday 29 October 2015 22:58:28 Tina Ruchandani wrote:
> struct timeval' uses 32-bits for its seconds field and will overflow in
> the year 2038 and beyond. This patch replaces the usage of 'struct timeval'
> in mon_get_timestamp() with timespec64 which uses a 64-bit seconds field
> and is y2038-safe. mon_get_timestamp() truncates the timestamp at 4096 seconds,
> so the correctness of the code is not affected. This patch is part of a larger
> attempt to remove instances of struct timeval and other 32-bit timekeeping
> (time_t, struct timespec) from the kernel.
>
> Signed-off-by: Tina Ruchandani <ruchandani.tina@gmail.com>
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-05 16:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-30 5:58 [PATCH v2] USB: usbmon: Remove timeval usage for timestamp Tina Ruchandani
2015-11-05 16:19 ` 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.