From patchwork Wed Nov 25 15:13:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 7700071 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DFF16BF90C for ; Wed, 25 Nov 2015 15:13:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E28FF2088E for ; Wed, 25 Nov 2015 15:13:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC9632088D for ; Wed, 25 Nov 2015 15:13:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753653AbbKYPNl (ORCPT ); Wed, 25 Nov 2015 10:13:41 -0500 Received: from mout.kundenserver.de ([212.227.126.133]:63524 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752156AbbKYPNj (ORCPT ); Wed, 25 Nov 2015 10:13:39 -0500 Received: from wuerfel.localnet ([134.3.118.24]) by mrelayeu.kundenserver.de (mreue002) with ESMTPSA (Nemesis) id 0Lj9fL-1ac3lv3CAB-00dSu3; Wed, 25 Nov 2015 16:13:28 +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 3/3] staging: media: lirc: Replace timeval with ktime_t in lirc_parallel.c Date: Wed, 25 Nov 2015 16:13:26 +0100 Message-ID: <4716726.5GsAHSDJCO@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <3966611.mJGTQOXNKU@wuerfel> References: <3966611.mJGTQOXNKU@wuerfel> MIME-Version: 1.0 X-Provags-ID: V03:K0:mTFR23szz0iIN5FXHSlcDwRcEN1qwu64oMKGKOiH6KMArab2pKi iW0Wd9SEk7uiZLmrZsAThUyUzQAswGb7ELeQLn/c9K+kXpLQxDVF+bgqh1SBXwAw9pn9Bug aCzcr8xZ3A/UdRQhttgn3+KkrLSpUlvflY7iMKzzlvj16nb68yPQ6l7qismQ4HUID3ZRCMZ 8OgdtqgyCvJnMzK8JOQzQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:/chppBS1RBo=:UPkg4u3VZsN0pInRufe753 OG4yu1dqnqLAllVwBfrvnmkJOnUvkffcBlyHG6jEbJXC0DDGTjeVu0Sj0+qPQKalNidtM9BLU BYowSKxUi3xkfVnS5OQsszHBlKv7YkcbJct2xbO/lOmj/CZU0nQEdDY/MFlUT3cSopftWcwfO np/JOlSZPRhnRhTrwIPzKcF5t0FkCBSq7KSZ2VrhFxyPgguLXzzAF+1vxtBBzE918jwEql3RC qxU1PgrJ2MvO3ANYLmBLwe2T9ClTZJHizu2mrZJC+Z638Ql5aODHm3xzII9BaWsUmVFfpC9bx dKC4mngqp+vOO01sC4i/RHX1ME3pWEGWVd2AG+0RS0t85lz9862vPRL3FTE5WAUneVRJAqhR2 HOEIZtSoLMwkNjw6hah3dpMPp9pJkVRLoGz+zExmYQgpNJTUZmR8NM0AOax/HdZeGdvu+9yDY 9st1o+NA07BM+RBxhCWHN/R7ztRhCGMshx8EQ+6Miz5M3CeAx6FdfsYauudVeeZTcyfbn22WJ sxvT5s4PXRgRVg5PiXz/XhJrUnSyZTkTK3ZDbXn3fu+o0aNHMueKnRV8eX5pPGQgXmtxPWBUH h9nmueRtCAI361mJaNwiJH0x9gvrIq5KNX+zhQMZk2XciygN10s9bSpqCsARgCjBRlm204oYD lfDYGx8xMwtq4o3gj3oB2FQOE1wdGG351QcE4XX0s69Scufte+KV3iqu7UhLs7LzpRAjbW5nn 6w0MfzwIbb3G+8Q/ 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=ham 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 tv' and 'struct timeval now' is used to calculate the elapsed time. 'LIRC_SFH506_DELAY' is a delay t_phl in usecs. 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 lirc_parallel.c file of media: lirc driver to use ktime_t. ktime_get() is better than using do_gettimeofday(), because it uses the monotonic clock. ktime_sub is used to subtract two ktime variables. ktime_to_us() is used to convert ktime to microsecond. New ktime_t variable timeout, is added in lirc_off(),to improve clarity. Introduced a new ktime_t variable in lirc_lirc_irq_handler() function, to avoid the use of signal variable for storing seconds in the first part of this fucntion as later it uses a time unit that is defined by the global "timer" variable. This makes it more clear. ktime_set() is used to set a value in seconds to a value in nanosecond so that ktime_compare() can be used appropriately. ktime_compare() is used to compare two ktime values. ktime_add_ns() is used to increment a ktime value by 1 sec. One comment is also shifted a line up, as it was creating a 80 character warning. Build tested it. Also tested it with sparse. 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_parallel.c b/drivers/staging/media/lirc/lirc_parallel.c index c1408342b1d0..c7987c01d9e0 100644 --- a/drivers/staging/media/lirc/lirc_parallel.c +++ b/drivers/staging/media/lirc/lirc_parallel.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include @@ -144,25 +144,22 @@ static void lirc_off(void) static unsigned int init_lirc_timer(void) { - struct timeval tv, now; + ktime_t kt, now, timeout; unsigned int level, newlevel, timeelapsed, newtimer; int count = 0; - do_gettimeofday(&tv); - tv.tv_sec++; /* wait max. 1 sec. */ + kt = ktime_get(); + /* wait max. 1 sec. */ + timeout = ktime_add_ns(kt, NSEC_PER_SEC); level = lirc_get_timer(); do { newlevel = lirc_get_timer(); if (level == 0 && newlevel != 0) count++; level = newlevel; - do_gettimeofday(&now); - } while (count < 1000 && (now.tv_sec < tv.tv_sec - || (now.tv_sec == tv.tv_sec - && now.tv_usec < tv.tv_usec))); - - timeelapsed = (now.tv_sec + 1 - tv.tv_sec)*1000000 - + (now.tv_usec - tv.tv_usec); + now = ktime_get(); + } while (count < 1000 && (ktime_before(now, timeout))); + timeelapsed = ktime_us_delta(now, kt); if (count >= 1000 && timeelapsed > 0) { if (default_timer == 0) { /* autodetect timer */ @@ -220,8 +217,8 @@ static void rbuf_write(int signal) static void lirc_lirc_irq_handler(void *blah) { - struct timeval tv; - static struct timeval lasttv; + ktime_t kt, delkt; + static ktime_t lastkt; static int init; long signal; int data; @@ -244,16 +241,14 @@ static void lirc_lirc_irq_handler(void *blah) #ifdef LIRC_TIMER if (init) { - do_gettimeofday(&tv); + kt = ktime_get(); - signal = tv.tv_sec - lasttv.tv_sec; - if (signal > 15) + delkt = ktime_sub(kt, lastkt); + if (ktime_compare(delkt, ktime_set(15, 0)) > 0) /* really long time */ data = PULSE_MASK; else - data = (int) (signal*1000000 + - tv.tv_usec - lasttv.tv_usec + - LIRC_SFH506_DELAY); + data = (int) (ktime_to_us(delkt) + LIRC_SFH506_DELAY); rbuf_write(data); /* space */ } else { @@ -301,7 +296,7 @@ static void lirc_lirc_irq_handler(void *blah) data = 1; rbuf_write(PULSE_BIT|data); /* pulse */ } - do_gettimeofday(&lasttv); + lastkt = ktime_get(); #else /* add your code here */ #endif