From dd28153b2a8ca216350a9f42de58cf3a966cba30 Mon Sep 17 00:00:00 2001 From: Somya Anand Date: Thu, 23 Oct 2014 21:28:37 +0200 Subject: [PATCH] Staging: comedi: replace timeval with ktime_t 'struct timeval last' is used for recording last time interrupt. 'struct timeval now' is used for calculating elapsed time. 32-bit systems using 'struct timeval' will break in the year 2038, so we have to replace that code with more appropriate types. This patch changes the comedi driver to use ktime_t. Since this code doesn't communicate the time values to the outside (user space, file system, network).Thus ktime_get() is a better than using do_gettimeofday() as it uses monotonic clock. ktime_to_us() returns an 's64', and using the '%' operator on that requires doing a 64-bit division which needs an expensive library function call the specific value of usec_current does not actually matter although it might matter that it's not always the same which will start with the offset from the lower 32 bit of the microsecond. Therefore: devpriv->usec_current = (ktime_to_us(devpriv->last) % USEC_PER_SEC) % devpriv->usec_period; is replaced by devpriv->usec_current = ((u32)ktime_to_us(devpriv->last)) % devpriv->usec_period; Signed-off-by: Somya Anand Signed-off-by: Arnd Bergmann Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/comedi_test.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c index 8845075cd3cc..4d4358ce1710 100644 --- a/drivers/staging/comedi/drivers/comedi_test.c +++ b/drivers/staging/comedi/drivers/comedi_test.c @@ -52,13 +52,14 @@ zero volts). #include "comedi_fc.h" #include +#include #define N_CHANS 8 /* Data unique to this driver */ struct waveform_private { struct timer_list timer; - struct timeval last; /* time last timer interrupt occurred */ + ktime_t last; /* time last timer interrupt occurred */ unsigned int uvolt_amplitude; /* waveform amplitude in microvolts */ unsigned long usec_period; /* waveform period in microseconds */ unsigned long usec_current; /* current time (mod waveform period) */ @@ -171,14 +172,12 @@ static void waveform_ai_interrupt(unsigned long arg) /* all times in microsec */ unsigned long elapsed_time; unsigned int num_scans; - struct timeval now; + ktime_t now; bool stopping = false; - do_gettimeofday(&now); + now = ktime_get(); - elapsed_time = - 1000000 * (now.tv_sec - devpriv->last.tv_sec) + now.tv_usec - - devpriv->last.tv_usec; + elapsed_time = ktime_to_us(ktime_sub(now, devpriv->last)); devpriv->last = now; num_scans = (devpriv->usec_remainder + elapsed_time) / devpriv->scan_period; @@ -317,8 +316,9 @@ static int waveform_ai_cmd(struct comedi_device *dev, else /* TRIG_TIMER */ devpriv->convert_period = cmd->convert_arg / nano_per_micro; - do_gettimeofday(&devpriv->last); - devpriv->usec_current = devpriv->last.tv_usec % devpriv->usec_period; + devpriv->last = ktime_get(); + devpriv->usec_current = + ((u32)ktime_to_us(devpriv->last)) % devpriv->usec_period; devpriv->usec_remainder = 0; devpriv->timer.expires = jiffies + 1; -- 2.30.2