From patchwork Wed Nov 25 15:12:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 7700061 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D5FEE9F2E9 for ; Wed, 25 Nov 2015 15:13:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F39B32088E for ; Wed, 25 Nov 2015 15:13:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7810420897 for ; Wed, 25 Nov 2015 15:13:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751881AbbKYPNK (ORCPT ); Wed, 25 Nov 2015 10:13:10 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:55885 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751637AbbKYPNJ (ORCPT ); Wed, 25 Nov 2015 10:13:09 -0500 Received: from wuerfel.localnet ([134.3.118.24]) by mrelayeu.kundenserver.de (mreue103) with ESMTPSA (Nemesis) id 0MIgBs-1a3nbn1LeC-002DH0; Wed, 25 Nov 2015 16:12:59 +0100 From: Arnd Bergmann To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, Jarod Wilson , Greg Kroah-Hartman , Tapasweni Pathak , y2038@lists.linaro.org Subject: [PATCH 2/3] staging: media: lirc: Replace timeval with ktime_t in lirc_sasem.c Date: Wed, 25 Nov 2015 16:12:53 +0100 Message-ID: <14705179.XxOpBT5U0L@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <3966611.mJGTQOXNKU@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h/c/W14ePAqEUsjB Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP '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: Tapasweni Pathak Reviewed-by: Arnd Bergmann Signed-off-by: Arnd Bergmann --- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/staging/media/lirc/lirc_sasem.c b/drivers/staging/media/lirc/lirc_sasem.c index f2dca69c2bc0..2218d0042030 100644 --- a/drivers/staging/media/lirc/lirc_sasem.c +++ b/drivers/staging/media/lirc/lirc_sasem.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -111,7 +112,7 @@ struct sasem_context { } tx; /* for dealing with repeat codes (wish there was a toggle bit!) */ - struct timeval presstime; + ktime_t presstime; char lastcode[8]; int codesaved; }; @@ -566,8 +567,8 @@ static void incoming_packet(struct sasem_context *context, { int len = urb->actual_length; unsigned char *buf = urb->transfer_buffer; - long ms; - struct timeval tv; + u64 ns; + ktime_t kt; if (len != 8) { dev_warn(&context->dev->dev, @@ -584,9 +585,8 @@ static void incoming_packet(struct sasem_context *context, */ /* get the time since the last button press */ - do_gettimeofday(&tv); - ms = (tv.tv_sec - context->presstime.tv_sec) * 1000 + - (tv.tv_usec - context->presstime.tv_usec) / 1000; + kt = ktime_get(); + ns = ktime_to_ns(ktime_sub(kt, context->presstime)); 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, * in that time and then get a false repeat of the previous * 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); - context->presstime.tv_sec = tv.tv_sec; - context->presstime.tv_usec = tv.tv_usec; + context->presstime = kt; } } else { /* save the current valid code for repeats */ @@ -613,8 +612,7 @@ static void incoming_packet(struct sasem_context *context, * just for safety reasons */ context->codesaved = 1; - context->presstime.tv_sec = tv.tv_sec; - context->presstime.tv_usec = tv.tv_usec; + context->presstime = kt; } lirc_buffer_write(context->driver->rbuf, buf);