Commit f07c73fe authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Mauro Carvalho Chehab

[media] staging: media: lirc: Replace timeval with ktime_t in lirc_sasem.c

'struct timeval presstime' and 'struct timeval tv' is used to
calculate the time since the last button press.

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 media: lirc driver to use ktime_t.

ktime_get() is  better than using do_gettimeofday(), because it uses
the monotonic clock. ktime_sub() are used to subtract two ktime
variables. 'ms' is only used to check how much time has passed by comparing
to 250. So instead of using expensive ktime_to_ms() call, it has been
changed to hold nanoseconds by using ktime_to_ns().

Build tested it. Tested with sparse too.
Signed-off-by: default avatarTapasweni Pathak <tapaswenipathak@gmail.com>
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent 84595032
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/ktime.h>
#include <media/lirc.h> #include <media/lirc.h>
#include <media/lirc_dev.h> #include <media/lirc_dev.h>
...@@ -111,7 +112,7 @@ struct sasem_context { ...@@ -111,7 +112,7 @@ struct sasem_context {
} tx; } tx;
/* for dealing with repeat codes (wish there was a toggle bit!) */ /* for dealing with repeat codes (wish there was a toggle bit!) */
struct timeval presstime; ktime_t presstime;
char lastcode[8]; char lastcode[8];
int codesaved; int codesaved;
}; };
...@@ -566,8 +567,8 @@ static void incoming_packet(struct sasem_context *context, ...@@ -566,8 +567,8 @@ static void incoming_packet(struct sasem_context *context,
{ {
int len = urb->actual_length; int len = urb->actual_length;
unsigned char *buf = urb->transfer_buffer; unsigned char *buf = urb->transfer_buffer;
long ms; u64 ns;
struct timeval tv; ktime_t kt;
if (len != 8) { if (len != 8) {
dev_warn(&context->dev->dev, dev_warn(&context->dev->dev,
...@@ -584,9 +585,8 @@ static void incoming_packet(struct sasem_context *context, ...@@ -584,9 +585,8 @@ static void incoming_packet(struct sasem_context *context,
*/ */
/* get the time since the last button press */ /* get the time since the last button press */
do_gettimeofday(&tv); kt = ktime_get();
ms = (tv.tv_sec - context->presstime.tv_sec) * 1000 + ns = ktime_to_ns(ktime_sub(kt, context->presstime));
(tv.tv_usec - context->presstime.tv_usec) / 1000;
if (memcmp(buf, "\x08\0\0\0\0\0\0\0", 8) == 0) { if (memcmp(buf, "\x08\0\0\0\0\0\0\0", 8) == 0) {
/* /*
...@@ -600,10 +600,9 @@ static void incoming_packet(struct sasem_context *context, ...@@ -600,10 +600,9 @@ static void incoming_packet(struct sasem_context *context,
* in that time and then get a false repeat of the previous * in that time and then get a false repeat of the previous
* press but it is long enough for a genuine repeat * press but it is long enough for a genuine repeat
*/ */
if ((ms < 250) && (context->codesaved != 0)) { if ((ns < 250 * NSEC_PER_MSEC) && (context->codesaved != 0)) {
memcpy(buf, &context->lastcode, 8); memcpy(buf, &context->lastcode, 8);
context->presstime.tv_sec = tv.tv_sec; context->presstime = kt;
context->presstime.tv_usec = tv.tv_usec;
} }
} else { } else {
/* save the current valid code for repeats */ /* save the current valid code for repeats */
...@@ -613,8 +612,7 @@ static void incoming_packet(struct sasem_context *context, ...@@ -613,8 +612,7 @@ static void incoming_packet(struct sasem_context *context,
* just for safety reasons * just for safety reasons
*/ */
context->codesaved = 1; context->codesaved = 1;
context->presstime.tv_sec = tv.tv_sec; context->presstime = kt;
context->presstime.tv_usec = tv.tv_usec;
} }
lirc_buffer_write(context->driver->rbuf, buf); lirc_buffer_write(context->driver->rbuf, buf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment