From patchwork Wed Jul 29 12:18:31 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: 51660 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id 63F4E22DB5 for ; Wed, 29 Jul 2015 12:20:17 +0000 (UTC) Received: by lbvb1 with SMTP id b1sf3240954lbv.3 for ; Wed, 29 Jul 2015 05:20:16 -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=Rn5BSbOYVXaO3zIEjWX1SME2YuFxstZfyP1dxh7ihyyWQ05Pakyg0rCBJarLtXYn7I 8c7W0q62u89IGuxDc9cNXW8qMf1/H8KpDKgPEWZTJlbC0cn+fWcAinG9CXa7SfsRdL6l NWOyBRWKglHu+1tGThDJaWAa6jkkYnufkTjCc3mHKQkFQE609jZ6CUkJqniNCNX7y65U STQrwoC+TNJYgGRrEGZw2h6uK39nQWgF7TEqii36RcKnw0IeAqPmQWT+2VWRSvZOp72h bXSjnKe0KDyzdpv8cqdCuycq2K0nvGIggVbQ/nE+EotbRAQgsoInlltGTGvmuH10Jd46 VBBA== X-Gm-Message-State: ALoCoQldITy0C750cI6VtOtHKrtsEXdvQWzdhKB/z1qoJ9VOe6oiuO+DWx8ER/PoOYoWbEjNCip+ X-Received: by 10.194.219.234 with SMTP id pr10mr3611166wjc.2.1438172416312; Wed, 29 Jul 2015 05:20:16 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.105 with SMTP id i9ls33802laa.96.gmail; Wed, 29 Jul 2015 05:20:15 -0700 (PDT) X-Received: by 10.152.42.144 with SMTP id o16mr38304878lal.46.1438172415867; Wed, 29 Jul 2015 05:20:15 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id k11si21383967lbz.74.2015.07.29.05.20.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jul 2015 05:20:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by laah7 with SMTP id h7so5101278laa.0 for ; Wed, 29 Jul 2015 05:20:15 -0700 (PDT) X-Received: by 10.152.36.102 with SMTP id p6mr38473559laj.19.1438172415422; Wed, 29 Jul 2015 05:20:15 -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.7.198 with SMTP id l6csp2721114lba; Wed, 29 Jul 2015 05:20:14 -0700 (PDT) X-Received: by 10.107.29.5 with SMTP id d5mr895835iod.193.1438172414261; Wed, 29 Jul 2015 05:20:14 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si3013370pds.168.2015.07.29.05.19.44; Wed, 29 Jul 2015 05:20:14 -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 S1752958AbbG2MTm (ORCPT + 27 others); Wed, 29 Jul 2015 08:19:42 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:33152 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751445AbbG2MTl (ORCPT ); Wed, 29 Jul 2015 08:19:41 -0400 Received: by pdbnt7 with SMTP id nt7so5247633pdb.0 for ; Wed, 29 Jul 2015 05:19:41 -0700 (PDT) X-Received: by 10.70.87.195 with SMTP id ba3mr94132377pdb.154.1438172381128; Wed, 29 Jul 2015 05:19:41 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id pe3sm40539379pdb.55.2015.07.29.05.19.38 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Jul 2015 05:19:40 -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 v2 5/5] time: Introduce timespec64_to_jiffies()/jiffies_to_timespec64() Date: Wed, 29 Jul 2015 20:18:31 +0800 Message-Id: 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.215.43 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