From patchwork Fri Oct 23 08:53:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WEN Pingbo X-Patchwork-Id: 7470871 Return-Path: X-Original-To: patchwork-linux-input@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 A6B4DBEEA4 for ; Fri, 23 Oct 2015 08:54:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AAA58208C6 for ; Fri, 23 Oct 2015 08:54:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D11F207E9 for ; Fri, 23 Oct 2015 08:54:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751711AbbJWIyS (ORCPT ); Fri, 23 Oct 2015 04:54:18 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:34093 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751541AbbJWIyP (ORCPT ); Fri, 23 Oct 2015 04:54:15 -0400 Received: by padhk11 with SMTP id hk11so113084443pad.1 for ; Fri, 23 Oct 2015 01:54:14 -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=yDDN+gwcKQmUlH8XJXgvDXwLQam7OWcEvO/67mj/+l0=; b=SZfsPQ6mBPIesYGs+nGOXXR6cHeQY9Gt1cGbVBueP+WiN8YyDFP6i3ZW5oi9Gn5PI7 d454XWbph0lnt28dwksICGGqyczaNfAUVo/iO8u1+LWr5/LL8WZpd3VWiOmifU97E6ip lvHn5Uy/KRFwCBkz0FSwzUMYepI27HKPG/xIKwkjYhD4SHZyP58PZoxrYSEpX/oAG+VT qOjYnfuHv51Fhn/OHyE7HIHtSDBXobm/dNyc0BczwEPcnPgIQog3QxDEQ/rR/4QAGU3C B/wKzm+3+iH6mIqs2e0ZcbtgF/7fkPkhNhvaMmH3rnGYljFAc6JLsp3/dZoowrkdHDF6 NLzQ== X-Gm-Message-State: ALoCoQkn7iimzca34lzK/B0fmw7IDhSkiWsrjJrOzJG8QZH9M3AehRCslSjEfe2yHjvDZ4YaJ8Mj X-Received: by 10.68.174.1 with SMTP id bo1mr3837623pbc.110.1445590454502; Fri, 23 Oct 2015 01:54:14 -0700 (PDT) Received: from localhost.localdomain (edge04.meizu.com. [103.26.122.10]) by smtp.gmail.com with ESMTPSA id ea5sm4481922pbc.92.2015.10.23.01.54.12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Oct 2015 01:54:13 -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 V2] hp_sdc: fixed y2038 problem Date: Fri, 23 Oct 2015 16:53:26 +0800 Message-Id: <1445590406-30448-1-git-send-email-pingbo.wen@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <5041745.xAgMz1TQSE@wuerfel> References: <5041745.xAgMz1TQSE@wuerfel> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.9 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 1. Converting timeval to ktime_t, and there is no need to handle sec and usec separately 2. hp_sdc.rtv is only used for time diff, monotonic time is better here Signed-off-by: WEN Pingbo --- drivers/input/serio/hp_sdc.c | 16 ++++++---------- include/linux/hp_sdc.h | 6 +++--- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/input/serio/hp_sdc.c b/drivers/input/serio/hp_sdc.c index 852858e..8ef82ee 100644 --- a/drivers/input/serio/hp_sdc.c +++ b/drivers/input/serio/hp_sdc.c @@ -193,7 +193,7 @@ static void hp_sdc_take(int irq, void *dev_id, uint8_t status, uint8_t data) curr->seq[curr->idx++] = status; curr->seq[curr->idx++] = data; hp_sdc.rqty -= 2; - do_gettimeofday(&hp_sdc.rtv); + hp_sdc.rtv = ktime_get(); if (hp_sdc.rqty <= 0) { /* All data has been gathered. */ @@ -306,13 +306,9 @@ static void hp_sdc_tasklet(unsigned long foo) write_lock_irq(&hp_sdc.rtq_lock); if (hp_sdc.rcurr >= 0) { - struct timeval tv; + ktime_t time_diff = ktime_sub(ktime_get(), hp_sdc.rtv); - do_gettimeofday(&tv); - if (tv.tv_sec > hp_sdc.rtv.tv_sec) - tv.tv_usec += USEC_PER_SEC; - - if (tv.tv_usec - hp_sdc.rtv.tv_usec > HP_SDC_MAX_REG_DELAY) { + if (time_diff.tv64 > HP_SDC_MAX_REG_DELAY) { hp_sdc_transaction *curr; uint8_t tmp; @@ -321,8 +317,8 @@ static void hp_sdc_tasklet(unsigned long foo) * we'll need to figure out a way to communicate * it back to the application. and be less verbose. */ - printk(KERN_WARNING PREFIX "read timeout (%ius)!\n", - (int)(tv.tv_usec - hp_sdc.rtv.tv_usec)); + printk(KERN_WARNING PREFIX "read timeout (%llins)!\n", + time_diff.tv64); curr->idx += hp_sdc.rqty; hp_sdc.rqty = 0; tmp = curr->seq[curr->actidx]; @@ -551,7 +547,7 @@ unsigned long hp_sdc_put(void) /* Start a new read */ hp_sdc.rqty = curr->seq[curr->idx]; - do_gettimeofday(&hp_sdc.rtv); + hp_sdc.rtv = ktime_get(); curr->idx++; /* Still need to lock here in case of spurious irq. */ write_lock_irq(&hp_sdc.rtq_lock); diff --git a/include/linux/hp_sdc.h b/include/linux/hp_sdc.h index d392975..348a9b5 100644 --- a/include/linux/hp_sdc.h +++ b/include/linux/hp_sdc.h @@ -47,9 +47,9 @@ #endif -/* No 4X status reads take longer than this (in usec). +/* No 4X status reads take longer than this (in nsec). */ -#define HP_SDC_MAX_REG_DELAY 20000 +#define HP_SDC_MAX_REG_DELAY 20000000 typedef void (hp_sdc_irqhook) (int irq, void *dev_id, uint8_t status, uint8_t data); @@ -281,7 +281,7 @@ typedef struct { hp_sdc_transaction *tq[HP_SDC_QUEUE_LEN]; /* All pending read/writes */ int rcurr, rqty; /* Current read transact in process */ - struct timeval rtv; /* Time when current read started */ + ktime_t rtv; /* Time when current read started */ int wcurr; /* Current write transact in process */ int dev_err; /* carries status from registration */