From patchwork Mon Aug 17 20:41:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 52483 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 patches.linaro.org (Postfix) with ESMTPS id 8DEA82156D for ; Mon, 17 Aug 2015 20:41:34 +0000 (UTC) Received: by labth1 with SMTP id th1sf50904315lab.2 for ; Mon, 17 Aug 2015 13:41:33 -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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=IXOeM4qLKU0E6P5BP3LpJzSmMAsFph8xrKPas9SFXGw=; b=Sw/sStvCG9vynbj3nVK+amgWnEi7roXA0Ta45pB97+0v4nQzO7SM7osdoBOeU8ZKBG 5v7XDeSZetcYhKAHUjRDwLnrbl99j+behxIFZbUtommhUimNVyUygKyetsMs4+cH+cV4 w/p8dDC3LDF2e6oAwImRd76LBYpM+vhpU9EYsAsxgHvd/tvz2BKmZqGEtlpuHh9CUbmn GAo7ksx/wQoi47e3+I9G8EP2g0sfVS2x9/2ZQMLS+WBFKPhgpInHl5dUzTD7rzH7PK53 VeQ4jLW5moQEXPR4eyINr8dOpDMtGPz+eexiAxvSJaFF+qdUxC2ajDLRUMpSHckrCN18 LbCA== X-Gm-Message-State: ALoCoQl0X9c+OLjsJ1jKVtYby5245GQUayQ5CssON1Q/wGlWXN9i7ViYLOUXdrZ7g7EzAJjHMPVh X-Received: by 10.194.71.39 with SMTP id r7mr796807wju.0.1439844093513; Mon, 17 Aug 2015 13:41:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.106 with SMTP id kx10ls679184lac.51.gmail; Mon, 17 Aug 2015 13:41:33 -0700 (PDT) X-Received: by 10.152.29.132 with SMTP id k4mr2640032lah.88.1439844093344; Mon, 17 Aug 2015 13:41:33 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id cj1si12359204lad.109.2015.08.17.13.41.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Aug 2015 13:41:33 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by labd1 with SMTP id d1so87273284lab.1 for ; Mon, 17 Aug 2015 13:41:33 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr2601773lbc.41.1439844093225; Mon, 17 Aug 2015 13:41:33 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.162.200 with SMTP id yc8csp85995lbb; Mon, 17 Aug 2015 13:41:31 -0700 (PDT) X-Received: by 10.66.160.1 with SMTP id xg1mr6049900pab.27.1439844078723; Mon, 17 Aug 2015 13:41:18 -0700 (PDT) Received: from mail-pa0-f47.google.com (mail-pa0-f47.google.com. [209.85.220.47]) by mx.google.com with ESMTPS id bw14si26351802pac.33.2015.08.17.13.41.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Aug 2015 13:41:18 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.47 as permitted sender) client-ip=209.85.220.47; Received: by pawq9 with SMTP id q9so18142647paw.3 for ; Mon, 17 Aug 2015 13:41:17 -0700 (PDT) X-Received: by 10.66.241.130 with SMTP id wi2mr6112591pac.130.1439844077838; Mon, 17 Aug 2015 13:41:17 -0700 (PDT) Received: from localhost.localdomain (c-76-115-103-22.hsd1.or.comcast.net. [76.115.103.22]) by smtp.gmail.com with ESMTPSA id gu2sm85199pbc.1.2015.08.17.13.41.16 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Aug 2015 13:41:16 -0700 (PDT) From: John Stultz To: lkml Cc: Baolin Wang , Prarit Bhargava , Richard Cochran , Ingo Molnar , Thomas Gleixner , John Stultz Subject: [PATCH 7/9] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64() Date: Mon, 17 Aug 2015 13:41:01 -0700 Message-Id: <1439844063-7957-8-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1439844063-7957-1-git-send-email-john.stultz@linaro.org> References: <1439844063-7957-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@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.41 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Baolin Wang 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. Cc: Prarit Bhargava Cc: Richard Cochran Cc: Ingo Molnar Cc: Thomas Gleixner Signed-off-by: Baolin Wang Signed-off-by: John Stultz --- include/linux/jiffies.h | 22 +++++++++++++++++++--- kernel/time/time.c | 21 +++++++++++++-------- 2 files changed, 32 insertions(+), 11 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 34dbd42..f18ab10 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -540,7 +540,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; @@ -548,22 +548,27 @@ __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; } -unsigned long -timespec_to_jiffies(const struct timespec *value) +static unsigned long +__timespec_to_jiffies(unsigned long sec, long nsec) { - return __timespec_to_jiffies(value->tv_sec, value->tv_nsec); + return __timespec64_to_jiffies((u64)sec, nsec); } -EXPORT_SYMBOL(timespec_to_jiffies); +unsigned long +timespec64_to_jiffies(const struct timespec64 *value) +{ + return __timespec64_to_jiffies(value->tv_sec, value->tv_nsec); +} +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 @@ -574,7 +579,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