From patchwork Fri Jun 12 08:06:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 49812 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8DD1D20C81 for ; Fri, 12 Jun 2015 08:08:00 +0000 (UTC) Received: by labby2 with SMTP id by2sf8563720lab.1 for ; Fri, 12 Jun 2015 01:07:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=0KnRimsTxnQOkMmW+sCEUZCcZJddDUFtLk6PciQpK3o=; b=bYI42D1hYUoDWS121DoD4FMMtA7HDeg65gMJLi9s3OPnbijFuqTuYIp20oVN4cf3DV 2cJySgA7ZHTcBblyDgQaHWqECU4tHey1Rd5R60xq9qaUyBOBKW1SKZLEvUhJE/P5JHAL J1ElaxKgSi119Cc7DH387e5QEw9u4JppepWfxyQe7rF13T142cbXoEgL1nxb9up7NJZk wxbIoCQV+FgiN9qrk64BdqAzA5myfwG/ll7sawjlWfZY2i0vB1rl8bWWSj4fFK7PI8sE ZlGbsuDSNe8I+38btB00YUfEPTucgZT5fyY7ZO5CBgQ/KF3xTg5ylL5gqp4Qepa10irk Fq6A== X-Gm-Message-State: ALoCoQkXm79A0fMbnsdhgXpNT4Gc25Xo1rEVxI1Ye7r4Qea14kvIAFKlCImrPjNXo6t+aZ5TM8dP X-Received: by 10.152.42.208 with SMTP id q16mr13049697lal.9.1434096479534; Fri, 12 Jun 2015 01:07:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.9 with SMTP id ky9ls449804lab.98.gmail; Fri, 12 Jun 2015 01:07:59 -0700 (PDT) X-Received: by 10.112.63.201 with SMTP id i9mr13751671lbs.93.1434096479358; Fri, 12 Jun 2015 01:07:59 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id qf8si2765696lbb.91.2015.06.12.01.07.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 01:07:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by lagh7 with SMTP id h7so6594505lag.0 for ; Fri, 12 Jun 2015 01:07:58 -0700 (PDT) X-Received: by 10.112.222.133 with SMTP id qm5mr13951764lbc.86.1434096478152; Fri, 12 Jun 2015 01:07:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp365607lbb; Fri, 12 Jun 2015 01:07:57 -0700 (PDT) X-Received: by 10.68.135.233 with SMTP id pv9mr21563339pbb.115.1434096476393; Fri, 12 Jun 2015 01:07:56 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q2si4348445pap.44.2015.06.12.01.07.54; Fri, 12 Jun 2015 01:07:56 -0700 (PDT) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753469AbbFLIHu (ORCPT + 29 others); Fri, 12 Jun 2015 04:07:50 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:35176 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751164AbbFLIHr (ORCPT ); Fri, 12 Jun 2015 04:07:47 -0400 Received: by pacyx8 with SMTP id yx8so18502584pac.2 for ; Fri, 12 Jun 2015 01:07:47 -0700 (PDT) X-Received: by 10.66.55.66 with SMTP id q2mr21234656pap.94.1434096467347; Fri, 12 Jun 2015 01:07:47 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by mx.google.com with ESMTPSA id g2sm2807177pdh.11.2015.06.12.01.07.44 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jun 2015 01:07:46 -0700 (PDT) From: Baolin Wang To: tglx@linutronix.de Cc: arnd@arndb.de, john.stultz@linaro.org, hofrat@osadl.org, ahh@google.com, linux-kernel@vger.kernel.org, baolin.wang@linaro.org, y2038@lists.linaro.org Subject: [PATCH v5 21/24] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64() Date: Fri, 12 Jun 2015 16:06:32 +0800 Message-Id: <9c45397ee16e79e864011c263c2ae711e2c6af1a.1434079263.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: baolin.wang@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The conversion between struct timespec and jiffies is not year 2038 safe on 32bit systems. Introduce timespec64_to_jiffies() and jiffies_to_timespec64() functions which use struct timespec64 to make it ready for 2038 issue. Signed-off-by: Baolin Wang --- include/linux/jiffies.h | 21 ++++++++++++++++++--- kernel/time/time.c | 11 ++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h index 3bde5eb..be37eae 100644 --- a/include/linux/jiffies.h +++ b/include/linux/jiffies.h @@ -363,9 +363,24 @@ static inline unsigned long msecs_to_jiffies(const unsigned int m) } extern unsigned long usecs_to_jiffies(const unsigned int u); -extern unsigned long timespec_to_jiffies(const struct timespec *value); -extern void jiffies_to_timespec(const unsigned long jiffies, - struct timespec *value); +extern unsigned long __timespec_to_jiffies(unsigned long sec, long nsec); +extern unsigned long timespec64_to_jiffies(const struct timespec64 *value); +extern void jiffies_to_timespec64(const unsigned long jiffies, + struct timespec64 *value); +static inline unsigned long timespec_to_jiffies(const struct timespec *value) +{ + return __timespec_to_jiffies(value->tv_sec, value->tv_nsec); +} + +static inline void jiffies_to_timespec(const unsigned long jiffies, + struct timespec *value) +{ + struct timespec64 ts; + + jiffies_to_timespec64(jiffies, &ts); + *value = timespec64_to_timespec(ts); +} + extern unsigned long timeval_to_jiffies(const struct timeval *value); extern void jiffies_to_timeval(const unsigned long jiffies, struct timeval *value); diff --git a/kernel/time/time.c b/kernel/time/time.c index 5aefe2d..8318cab 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -552,7 +552,7 @@ EXPORT_SYMBOL(usecs_to_jiffies); * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec * value to a scaled second value. */ -static unsigned long +unsigned long __timespec_to_jiffies(unsigned long sec, long nsec) { nsec = nsec + TICK_NSEC - 1; @@ -566,17 +566,18 @@ __timespec_to_jiffies(unsigned long sec, long nsec) (NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC; } +EXPORT_SYMBOL(__timespec_to_jiffies); unsigned long -timespec_to_jiffies(const struct timespec *value) +timespec64_to_jiffies(const struct timespec64 *value) { return __timespec_to_jiffies(value->tv_sec, value->tv_nsec); } -EXPORT_SYMBOL(timespec_to_jiffies); +EXPORT_SYMBOL(timespec64_to_jiffies); void -jiffies_to_timespec(const unsigned long jiffies, struct timespec *value) +jiffies_to_timespec64(const unsigned long jiffies, struct timespec64 *value) { /* * Convert jiffies to nanoseconds and separate with @@ -587,7 +588,7 @@ jiffies_to_timespec(const unsigned long jiffies, struct timespec *value) NSEC_PER_SEC, &rem); value->tv_nsec = rem; } -EXPORT_SYMBOL(jiffies_to_timespec); +EXPORT_SYMBOL(jiffies_to_timespec64); /* * We could use a similar algorithm to timespec_to_jiffies (with a