From patchwork Wed Jul 15 06:04:10 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: 51118 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8B9FD202B9 for ; Wed, 15 Jul 2015 06:05:29 +0000 (UTC) Received: by lbvb1 with SMTP id b1sf7795890lbv.3 for ; Tue, 14 Jul 2015 23:05:28 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=r4/Go+ZITQFe6JZG4aPRqokG4gKOUv1dWdcsOz3KIU0=; b=k8qyMfCPaXRTaqmRM/wfuGpVDXMO3bxZqeRNCLakD81y8Gc0AOcgX+IOWwyivW3IfW j/7fUNgZvR/u5RlF3bpm+MZCQ5p1pBX26GDZ46FfINwgNQ9OgK5YSfIxkhF5g+ymngJ6 WDVGzCA3UryLQOXHywknslwsNRLsSAavMJ9PSqRE0VxVONfBBp0d8Q/214SSjZkvAY/n vAXUbyMylsNEhbpKdII0YXJJAs1HXKAjU/IgPk/lRugH5OlVGoUSa5QynRcFsd+YefWB uDO+Jl0n+jcMcLrAiGTKonFlCJWgYnB31vPLdG+olCEqU0Of2oAtXn9tbkJ6PS991EOd ZM7g== X-Gm-Message-State: ALoCoQnqomiW81y4ziB1jE2KC9LCmosAzgQsoVqtEVqWLShh5DXPM/QQ0Q+Qy+F01sXTCF6xzfHy X-Received: by 10.112.138.2 with SMTP id qm2mr1226173lbb.19.1436940328162; Tue, 14 Jul 2015 23:05:28 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.227 with SMTP id n3ls154400lan.0.gmail; Tue, 14 Jul 2015 23:05:27 -0700 (PDT) X-Received: by 10.112.144.69 with SMTP id sk5mr2399328lbb.6.1436940327847; Tue, 14 Jul 2015 23:05:27 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id e14si3021766lbo.160.2015.07.14.23.05.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Jul 2015 23:05:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbbzr7 with SMTP id zr7so18493551lbb.1 for ; Tue, 14 Jul 2015 23:05:27 -0700 (PDT) X-Received: by 10.152.36.161 with SMTP id r1mr2352387laj.88.1436940327703; Tue, 14 Jul 2015 23:05:27 -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 hn6csp2847518lbb; Tue, 14 Jul 2015 23:05:26 -0700 (PDT) X-Received: by 10.66.234.134 with SMTP id ue6mr4655447pac.146.1436940325876; Tue, 14 Jul 2015 23:05:25 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zq10si5709327pac.96.2015.07.14.23.05.25; Tue, 14 Jul 2015 23:05:25 -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 S1751956AbbGOGFX (ORCPT + 26 others); Wed, 15 Jul 2015 02:05:23 -0400 Received: from mail-pd0-f179.google.com ([209.85.192.179]:33193 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751032AbbGOGFW (ORCPT ); Wed, 15 Jul 2015 02:05:22 -0400 Received: by pdbqm3 with SMTP id qm3so18913090pdb.0 for ; Tue, 14 Jul 2015 23:05:22 -0700 (PDT) X-Received: by 10.66.147.131 with SMTP id tk3mr4772284pab.104.1436940322049; Tue, 14 Jul 2015 23:05:22 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id ri11sm3230656pbb.92.2015.07.14.23.05.19 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Jul 2015 23:05:21 -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 5/6] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64() Date: Wed, 15 Jul 2015 14:04:10 +0800 Message-Id: <5101c4360c80490cb11ec9c06f6d43db471881cb.1436511577.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 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.217.173 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 | 22 +++++++++++++++++++--- kernel/time/time.c | 20 +++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h index 535fd3b..bf96d9f 100644 --- a/include/linux/jiffies.h +++ b/include/linux/jiffies.h @@ -416,9 +416,25 @@ static inline 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 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) +{ + struct timespec64 ts = timespec_to_timespec64(*value); + + return timespec64_to_jiffies(&ts); +} + +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 5d00da4..6692f5a 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -546,7 +546,7 @@ EXPORT_SYMBOL(__usecs_to_jiffies); * value to a scaled second value. */ static unsigned long -__timespec_to_jiffies(unsigned long sec, long nsec) +__timespec64_to_jiffies(u64 sec, long nsec) { nsec = nsec + TICK_NSEC - 1; @@ -554,22 +554,28 @@ __timespec_to_jiffies(unsigned long sec, long nsec) sec = MAX_SEC_IN_JIFFIES; nsec = 0; } - return (((u64)sec * SEC_CONVERSION) + + return ((sec * SEC_CONVERSION) + (((u64)nsec * NSEC_CONVERSION) >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC; } +static unsigned long +__timespec_to_jiffies(unsigned long sec, long nsec) +{ + return __timespec64_to_jiffies((u64)sec, nsec); +} + 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); + return __timespec64_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 @@ -580,7 +586,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