Skip to content

Commit ec4dca8

Browse files
Tinabr7gregkh
authored andcommitted
USB: usbmon: Remove timeval usage for timestamp
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 <[email protected]> Suggested-by: Arnd Bergmann <[email protected]> Reviewed-by: Arnd Bergmann <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9faae5a commit ec4dca8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/usb/mon/mon_text.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/usb.h>
1010
#include <linux/slab.h>
1111
#include <linux/time.h>
12+
#include <linux/ktime.h>
1213
#include <linux/export.h>
1314
#include <linux/mutex.h>
1415
#include <linux/debugfs.h>
@@ -176,12 +177,12 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
176177

177178
static inline unsigned int mon_get_timestamp(void)
178179
{
179-
struct timeval tval;
180+
struct timespec64 now;
180181
unsigned int stamp;
181182

182-
do_gettimeofday(&tval);
183-
stamp = tval.tv_sec & 0xFFF; /* 2^32 = 4294967296. Limit to 4096s. */
184-
stamp = stamp * 1000000 + tval.tv_usec;
183+
ktime_get_ts64(&now);
184+
stamp = now.tv_sec & 0xFFF; /* 2^32 = 4294967296. Limit to 4096s. */
185+
stamp = stamp * USEC_PER_SEC + now.tv_nsec / NSEC_PER_USEC;
185186
return stamp;
186187
}
187188

0 commit comments

Comments
 (0)