From patchwork Mon Nov 6 14:06:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10043539 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A3EFD602BF for ; Mon, 6 Nov 2017 14:07:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91B5E29CAE for ; Mon, 6 Nov 2017 14:07:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8609C29CB0; Mon, 6 Nov 2017 14:07:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3236729CAE for ; Mon, 6 Nov 2017 14:07:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932293AbdKFOGq (ORCPT ); Mon, 6 Nov 2017 09:06:46 -0500 Received: from mout.kundenserver.de ([212.227.126.130]:54932 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932287AbdKFOGo (ORCPT ); Mon, 6 Nov 2017 09:06:44 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue002 [212.227.15.129]) with ESMTPA (Nemesis) id 0MJsSS-1eCnyX0PuG-001D5e; Mon, 06 Nov 2017 15:06:33 +0100 From: Arnd Bergmann To: Mauro Carvalho Chehab Cc: Chunyan Zhang , Arnd Bergmann , Sean Young , Arvind Yadav , Hans Verkuil , Sakari Ailus , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: rc: Replace timeval with ktime_t in imon.c Date: Mon, 6 Nov 2017 15:06:10 +0100 Message-Id: <20171106140626.1601072-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:6j2XSyJtfOhc/kJ38qa5aMiZlmITaBs/eLRpokakclk+/4y8Cys rAf1czyXstrvY9UG9VO5oF0Vlicwmk1W7zrQ0R/cvJTj/HCRKzaFaZXbYedquCi9Xb8x+QM o6Ts3/ngbubG4W7ozGoJGNUpJkubtRJxqY9YrA/px1PtebqM3zTbW3qhsBk7ckhW0ClakVR nMHZzP2G798o2gMzB7cNA== X-UI-Out-Filterresults: notjunk:1; V01:K0:kZiIb3AbD8A=:J1D/hNAuDnj8bvI1nYfF8s gIseT2LHwfg+nxsAlmi8r91yIBPg0cbd2Se0GGBsdBQ8IaT3iKKHBMTcob7xqOWcGIbeMkIoz bvU4WavIbd2vGfubs9CktoQm1ZZdiV+NTcfDGGJoLMDjNLXJEX35G2E3ZZPTVmkrR03cJdWof q4DHJmH5wqcCVW4mBFls5z1XwqhRceb6GN2lYPTd/HH/H+2RQ5oBo4InbjngSRja4V/zwrNiG gCIG5Rsvas0kIcJgpCfQfZ5rZDs0JZbf7FX2jkSk/XsH3VxLff3iag3X3mD04tyygtQBZySW7 bcFgRBgHA/LWpXuMwPXgXgA54cPxY6TPyz0mhNHY9Gb3mprO0wO+efCJyGliXWskeFBD/3+EQ BanDeFgBVjZ4AcEjL1dXc+8qVrUUcx+JJaCq9eaqI7dD9u5EYIWzMEtkEiRRgffKK3CTFjUAJ sCVDtPQJ3E6CP7lr2c3bVCnor9YwdTkgUtCUqdHtjDYU0FFz+UxYSZhrO4XQutvHHHB/9O5bI PaVcV23hgv6YGeo6JK086oiOeBtb482c4Y0CeDmHkrbwb4yNNnhepXdigTealEL9wpBR4DMCO qvQG4nOIrzxnuFXBNZ6Pbcdk7A2VPH5yqUD4Y3LwLwlzKWF64eS0mYDS7IZftkcsC1Y+sJLyD 2kKTK2tXcotS5a0GhVZw5Xgrx8+E8gCRzNCQ/97SzM4zLIMSdyCHu8C3jQ1KJZX6I4nltheX/ 7+DzI+R44uj3cJedKHVdNir6voR0Oq1Zob8nCA== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Chunyan Zhang This patch changes the 32-bit time type (timeval) to the 64-bit one (ktime_t), since 32-bit time types will break in the year 2038. I use ktime_t instead of all uses of timeval in imon.c This patch also changes do_gettimeofday() to ktime_get() accordingly, since ktime_get returns a ktime_t, but do_gettimeofday returns a struct timeval, and the other reason is that ktime_get() uses the monotonic clock. Signed-off-by: Chunyan Zhang Acked-by: Mauro Carvalho Chehab Signed-off-by: Arnd Bergmann --- This patch was part of an old three-patch series, but did not get merged at the time after I dropped the ball on it. --- drivers/media/rc/imon.c | 49 +++++++++++++------------------------------------ 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c index b25b35b3f6da..6c3ca1fff16b 100644 --- a/drivers/media/rc/imon.c +++ b/drivers/media/rc/imon.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -37,7 +38,6 @@ #include #include -#include #include #define MOD_AUTHOR "Jarod Wilson " @@ -1168,29 +1168,6 @@ static int imon_ir_change_protocol(struct rc_dev *rc, u64 *rc_proto) return retval; } -static inline int tv2int(const struct timeval *a, const struct timeval *b) -{ - int usecs = 0; - int sec = 0; - - if (b->tv_usec > a->tv_usec) { - usecs = 1000000; - sec--; - } - - usecs += a->tv_usec - b->tv_usec; - - sec += a->tv_sec - b->tv_sec; - sec *= 1000; - usecs /= 1000; - sec += usecs; - - if (sec < 0) - sec = 1000; - - return sec; -} - /** * The directional pad behaves a bit differently, depending on whether this is * one of the older ffdc devices or a newer device. Newer devices appear to @@ -1201,16 +1178,16 @@ static inline int tv2int(const struct timeval *a, const struct timeval *b) */ static int stabilize(int a, int b, u16 timeout, u16 threshold) { - struct timeval ct; - static struct timeval prev_time = {0, 0}; - static struct timeval hit_time = {0, 0}; + ktime_t ct; + static ktime_t prev_time; + static ktime_t hit_time; static int x, y, prev_result, hits; int result = 0; - int msec, msec_hit; + long msec, msec_hit; - do_gettimeofday(&ct); - msec = tv2int(&ct, &prev_time); - msec_hit = tv2int(&ct, &hit_time); + ct = ktime_get(); + msec = ktime_ms_delta(ct, prev_time); + msec_hit = ktime_ms_delta(ct, hit_time); if (msec > 100) { x = 0; @@ -1688,9 +1665,9 @@ static void imon_incoming_scancode(struct imon_context *ictx, u32 kc; u64 scancode; int press_type = 0; - int msec; - struct timeval t; - static struct timeval prev_time = { 0, 0 }; + long msec; + ktime_t t; + static ktime_t prev_time; u8 ktype; /* filter out junk data on the older 0xffdc imon devices */ @@ -1783,10 +1760,10 @@ static void imon_incoming_scancode(struct imon_context *ictx, /* Only panel type events left to process now */ spin_lock_irqsave(&ictx->kc_lock, flags); - do_gettimeofday(&t); + t = ktime_get(); /* KEY_MUTE repeats from knob need to be suppressed */ if (ictx->kc == KEY_MUTE && ictx->kc == ictx->last_keycode) { - msec = tv2int(&t, &prev_time); + msec = ktime_ms_delta(t, prev_time); if (msec < ictx->idev->rep[REP_DELAY]) { spin_unlock_irqrestore(&ictx->kc_lock, flags); return;