From patchwork Sat Oct 24 04:00:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingbo Wen X-Patchwork-Id: 55513 Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp26183lbq; Fri, 23 Oct 2015 21:01:43 -0700 (PDT) X-Received: by 10.66.251.232 with SMTP id zn8mr27937454pac.80.1445659302931; Fri, 23 Oct 2015 21:01:42 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qy2si34590883pbb.55.2015.10.23.21.01.42 for ; Fri, 23 Oct 2015 21:01:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-input-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-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-input-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750780AbbJXEB2 (ORCPT ); Sat, 24 Oct 2015 00:01:28 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:35397 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751248AbbJXEA4 (ORCPT ); Sat, 24 Oct 2015 00:00:56 -0400 Received: by pasz6 with SMTP id z6so134439190pas.2 for ; Fri, 23 Oct 2015 21:00:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kRLv1/IZ52eJpt4BTig/xGnE9TtHWTjKezuMNZhI/yQ=; b=YjLYRCAsK3VVPea8CHKElr5ndSGh7Wcl2nFkehoTJwK1iiKZn0bXcDA/lMJlGuceid eu0ti4JFH97eC12NukmZNkiWxWwCxULUOOkwI8yImKiGP8OdOW92dZQbw2P+DUeKmTex 9V9TUjb+nPwPRZC0fOk2IsGRTqsLikxHzCq2DuPSXifChejnlLoymlC7ozMKp5KmQAQ9 /98OgjlRh1h6GKQk8DhT5fY9Vk36Gg3/PX0muwF37HclVGW+vWJJl1uH9NAc0oMPN1Rz Y/eyw760hEJ/LrusNrY0HMYNZQ1n2bFgpCaILG33jCLk+iPomIuKzD7WiJ7Ph5ni+uOG ZBkA== X-Gm-Message-State: ALoCoQlcodgk+Xflbr0akpmEf6eyFWInDxzEdyrSIBt6gHJuNujqjVYqvUI2WrIhZru0sRpILRf6 X-Received: by 10.68.200.104 with SMTP id jr8mr8749978pbc.91.1445659256042; Fri, 23 Oct 2015 21:00:56 -0700 (PDT) Received: from localhost.localdomain (edge03.meizu.com. [202.130.115.78]) by smtp.gmail.com with ESMTPSA id fb1sm21636320pab.9.2015.10.23.21.00.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Oct 2015 21:00:55 -0700 (PDT) From: WEN Pingbo To: arnd@arndb.de Cc: y2038@lists.linaro.org, dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, WEN Pingbo Subject: [PATCH V3 2/2] hil_mlc: convert timeval to jiffies Date: Sat, 24 Oct 2015 12:00:19 +0800 Message-Id: <1445659219-23135-2-git-send-email-pingbo.wen@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445659219-23135-1-git-send-email-pingbo.wen@linaro.org> References: <5201254.PnVcGHTDmH@wuerfel> <1445659219-23135-1-git-send-email-pingbo.wen@linaro.org> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org struct timeval is not y2038 safe, and what mlc->instart do is scheduling a task in a fixed timeout, so jiffies is the simplest choice here. In hilse_donode(), the expires in mod_timer equals jiffies + intimeout - (now - instart) If we use jiffies in 'now', the expires equals instart + intimeout So, all we need to do is that making sure expires is a future timestamp before passed it to mod_timer Signed-off-by: WEN Pingbo --- Version 2: Using ktime_t to fix y2038 problem Version 3: Convert it to jiffies drivers/input/serio/hil_mlc.c | 17 +++++++---------- drivers/input/serio/hp_sdc_mlc.c | 7 +++---- include/linux/hil_mlc.h | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-input" 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/input/serio/hil_mlc.c b/drivers/input/serio/hil_mlc.c index fb297aa..5428098 100644 --- a/drivers/input/serio/hil_mlc.c +++ b/drivers/input/serio/hil_mlc.c @@ -603,7 +603,7 @@ static inline void hilse_setup_input(hil_mlc *mlc, const struct hilse_node *node } mlc->istarted = 1; mlc->intimeout = node->arg; - do_gettimeofday(&(mlc->instart)); + mlc->instart = jiffies; mlc->icount = 15; memset(mlc->ipacket, 0, 16 * sizeof(hil_packet)); BUG_ON(down_trylock(&mlc->isem)); @@ -708,7 +708,7 @@ static int hilse_donode(hil_mlc *mlc) break; } mlc->ostarted = 0; - do_gettimeofday(&(mlc->instart)); + mlc->instart = jiffies; write_unlock_irqrestore(&mlc->lock, flags); nextidx = HILSEN_NEXT; break; @@ -729,18 +729,15 @@ static int hilse_donode(hil_mlc *mlc) #endif while (nextidx & HILSEN_SCHED) { - struct timeval tv; + unsigned long expires = mlc->instart + + usecs_to_jiffies(mlc->intimeout); if (!sched_long) goto sched; - do_gettimeofday(&tv); - tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec); - tv.tv_usec -= mlc->instart.tv_usec; - if (tv.tv_usec >= mlc->intimeout) goto sched; - tv.tv_usec = (mlc->intimeout - tv.tv_usec) * HZ / USEC_PER_SEC; - if (!tv.tv_usec) goto sched; - mod_timer(&hil_mlcs_kicker, jiffies + tv.tv_usec); + if (time_after_eq(jiffies, expires)) + goto sched; + mod_timer(&hil_mlcs_kicker, expires); break; sched: tasklet_schedule(&hil_mlcs_tasklet); diff --git a/drivers/input/serio/hp_sdc_mlc.c b/drivers/input/serio/hp_sdc_mlc.c index d50f067..b91d5bb 100644 --- a/drivers/input/serio/hp_sdc_mlc.c +++ b/drivers/input/serio/hp_sdc_mlc.c @@ -149,7 +149,6 @@ static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout) /* Try to down the semaphore */ if (down_trylock(&mlc->isem)) { - struct timeval tv; if (priv->emtestmode) { mlc->ipacket[0] = HIL_ERR_INT | (mlc->opacket & @@ -160,9 +159,9 @@ static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout) /* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */ goto wasup; } - do_gettimeofday(&tv); - tv.tv_usec += USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec); - if (tv.tv_usec - mlc->instart.tv_usec > mlc->intimeout) { + + if (time_after(jiffies, + mlc->instart + usecs_to_jiffies(mlc->intimeout))) { /* printk("!%i %i", tv.tv_usec - mlc->instart.tv_usec, mlc->intimeout); diff --git a/include/linux/hil_mlc.h b/include/linux/hil_mlc.h index 29bb5e3..feb167d 100644 --- a/include/linux/hil_mlc.h +++ b/include/linux/hil_mlc.h @@ -144,7 +144,7 @@ struct hil_mlc { hil_packet ipacket[16]; hil_packet imatch; int icount; - struct timeval instart; + unsigned long instart; /* in jiffies */ suseconds_t intimeout; int ddi; /* Last operational device id */