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: 118058 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2804507qgn; Mon, 6 Nov 2017 06:06:49 -0800 (PST) X-Google-Smtp-Source: ABhQp+SxtV2qFA04P8nFN6aIxyIa91XNXOEnfAdJrUClKA5w+jzyMEY3hRMl0uVvS1G8oAMXDvuW X-Received: by 10.98.87.207 with SMTP id i76mr17167915pfj.134.1509977209886; Mon, 06 Nov 2017 06:06:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509977209; cv=none; d=google.com; s=arc-20160816; b=Qtc+8EHIDS5iZCEfU29eMtO+hAevhaBlIOUxZ5ofymtPkLJ0wMdUvx7UqNU3BHyrpz HT/m978WrtfwoyZFPakCE95hN87zPh+1JUW+VIyY+GskNYLbfrc+d59Dr2E0DxrXoJsH zCPLryalRh+fbFXAhYSuNdg6e5MadauREkfY0qJPb1o7lUOsYXle6jk0/0fO4CcnDONT Yhk0SztDI1gBFhDYQS+Q8DaecN0onD3dd7wCLvLsamXdQI4R3wnOeuOo4CDCeC/pjPk/ J5gaRNVmOfo756Sp1G4HCGG18xTe7ZNFRcMUqb0PjyoqKP4/ACEYhPRsRmtvAUaqEFNf msYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=XSwMCASuVbVC3nQt+WoNOkOupwnOral5FLoEKuo1sok=; b=en3Hs1VlD60qYWB3erIMGuVXp+TDpWSqkfdHroN9eAnU5b9re8LKPK1zsRKT0zj/uQ nlUbMoCqYajkSKcPKZKTks19zIDaJHdtpudtrAqrUmSqyuwCatVKaHiTFUhu+wzu0Sf+ 4EsIaPPy7lkrFboIuaM0Qc1NxW8CJtsij/n5MvEFan0f/WfDErumjGJzJV0/LlcAmOBC r6xC7iNldpnktTlKQfL5N80i2Hy97KjAo31BC+tTUhBiM7lqlykudPlCFq+sBgI2oS0F rlx9sULTeOQUwK1p835uLwEwlIvF7k/xui6fJZPOXTB8AcxkXarVRlqyjMzgz+Ff/ljr Ne9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r8si10328200plo.828.2017.11.06.06.06.49; Mon, 06 Nov 2017 06:06:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932322AbdKFOGr (ORCPT + 26 others); Mon, 6 Nov 2017 09:06:47 -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: <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ltheX/ 7+DzI+R44uj3cJedKHVdNir6voR0Oq1Zob8nCA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.9.0 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;