From patchwork Fri Nov 21 19:44:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 41358 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3125525B55 for ; Fri, 21 Nov 2014 19:44:45 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id k14sf3363048wgh.4 for ; Fri, 21 Nov 2014 11:44:44 -0800 (PST) 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=KXrZbZYRSFEmTDXWRojYnGpvw6/HmJwh3Ij6sHpWZvA=; b=OcBokhoATNhUAvWYDc41z0ea9Ajf5KQ1sc7Ba/+bjFgs+OBGQpmPsn2ooRpw5YzCt0 4HLIt8RAkLTsjPl8onGwyHDtghjKDZgvVmwnG28l5ebau24iLRu/c98UAxF4zrTlOdhO 5uzESRnIr79ebTg0UP60UncxEUBqdhjl1SCJfF+/hglv0Iit8FfFj5lVauD4ZXUsxI8h 2AzgEw1QD3YueomU3dJ77ONVXHVzkd2RKaCwyOIbx6LQrT69wwZ08miBXuTJWXIB7P6i y+TyhsteBC/l/35QD40kdLVI3uXCC77pEXe5KB2e67NcIt3skDimB9Q/9l7u4b2rtRQN zZtw== X-Gm-Message-State: ALoCoQkzjeHCceY7CyFVAyePAtgJSVgMYZN3UqxnBSQBvm10rw/FObyij851AL2UspVWqVXKxa6s X-Received: by 10.112.55.10 with SMTP id n10mr1427771lbp.14.1416599084455; Fri, 21 Nov 2014 11:44:44 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.68 with SMTP id u4ls62750lal.47.gmail; Fri, 21 Nov 2014 11:44:44 -0800 (PST) X-Received: by 10.152.224.163 with SMTP id rd3mr7360889lac.24.1416599084309; Fri, 21 Nov 2014 11:44:44 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id t4si3687216laj.30.2014.11.21.11.44.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 11:44:44 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id p9so3710659lbv.28 for ; Fri, 21 Nov 2014 11:44:44 -0800 (PST) X-Received: by 10.152.8.170 with SMTP id s10mr7327641laa.56.1416599084224; Fri, 21 Nov 2014 11:44:44 -0800 (PST) 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.184.201 with SMTP id ew9csp153735lbc; Fri, 21 Nov 2014 11:44:43 -0800 (PST) X-Received: by 10.69.18.225 with SMTP id gp1mr10262652pbd.144.1416599081904; Fri, 21 Nov 2014 11:44:41 -0800 (PST) Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com. [209.85.220.53]) by mx.google.com with ESMTPS id qk3si10280695pbc.77.2014.11.21.11.44.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 11:44:41 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.53 as permitted sender) client-ip=209.85.220.53; Received: by mail-pa0-f53.google.com with SMTP id kq14so5514144pab.12 for ; Fri, 21 Nov 2014 11:44:41 -0800 (PST) X-Received: by 10.66.118.136 with SMTP id km8mr10645806pab.100.1416599081163; Fri, 21 Nov 2014 11:44:41 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id t9sm5513621pbs.75.2014.11.21.11.44.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Nov 2014 11:44:40 -0800 (PST) From: John Stultz To: lkml Cc: "pang.xunlei" , Thomas Gleixner , Ingo Molnar , Arnd Bergmann , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Alessandro Zummo , John Stultz Subject: [PATCH 06/12] time: Provide y2038 safe mktime() replacement Date: Fri, 21 Nov 2014 11:44:12 -0800 Message-Id: <1416599058-13836-7-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416599058-13836-1-git-send-email-john.stultz@linaro.org> References: <1416599058-13836-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.217.169 as permitted sender) smtp.mail=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: "pang.xunlei" As part of addressing "y2038 problem" for in-kernel uses, this patch adds safe mktime64() using time64_t. After this patch, mktime() is deprecated and all its call sites will be fixed using mktime64(), after that it can be removed. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Arnd Bergmann Cc: pang.xunlei Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Alessandro Zummo Signed-off-by: pang.xunlei Signed-off-by: John Stultz --- include/linux/time.h | 17 ++++++++++++++--- kernel/time/time.c | 20 ++++++++------------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/linux/time.h b/include/linux/time.h index 8c42cf8..203c2ad 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -39,9 +39,20 @@ static inline int timeval_compare(const struct timeval *lhs, const struct timeva return lhs->tv_usec - rhs->tv_usec; } -extern unsigned long mktime(const unsigned int year, const unsigned int mon, - const unsigned int day, const unsigned int hour, - const unsigned int min, const unsigned int sec); +extern time64_t mktime64(const unsigned int year, const unsigned int mon, + const unsigned int day, const unsigned int hour, + const unsigned int min, const unsigned int sec); + +/** + * Deprecated. Use mktime64(). + */ +static inline unsigned long mktime(const unsigned int year, + const unsigned int mon, const unsigned int day, + const unsigned int hour, const unsigned int min, + const unsigned int sec) +{ + return mktime64(year, mon, day, hour, min, sec); +} extern void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec); diff --git a/kernel/time/time.c b/kernel/time/time.c index a9ae20f..65015ff 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -304,7 +304,9 @@ struct timespec timespec_trunc(struct timespec t, unsigned gran) } EXPORT_SYMBOL(timespec_trunc); -/* Converts Gregorian date to seconds since 1970-01-01 00:00:00. +/* + * mktime64 - Converts date to seconds. + * Converts Gregorian date to seconds since 1970-01-01 00:00:00. * Assumes input in normal date format, i.e. 1980-12-31 23:59:59 * => year=1980, mon=12, day=31, hour=23, min=59, sec=59. * @@ -314,15 +316,10 @@ EXPORT_SYMBOL(timespec_trunc); * -year/100+year/400 terms, and add 10.] * * This algorithm was first published by Gauss (I think). - * - * WARNING: this function will overflow on 2106-02-07 06:28:16 on - * machines where long is 32-bit! (However, as time_t is signed, we - * will already get problems at other places on 2038-01-19 03:14:08) */ -unsigned long -mktime(const unsigned int year0, const unsigned int mon0, - const unsigned int day, const unsigned int hour, - const unsigned int min, const unsigned int sec) +time64_t mktime64(const unsigned int year0, const unsigned int mon0, + const unsigned int day, const unsigned int hour, + const unsigned int min, const unsigned int sec) { unsigned int mon = mon0, year = year0; @@ -332,15 +329,14 @@ mktime(const unsigned int year0, const unsigned int mon0, year -= 1; } - return ((((unsigned long) + return ((((time64_t) (year/4 - year/100 + year/400 + 367*mon/12 + day) + year*365 - 719499 )*24 + hour /* now have hours */ )*60 + min /* now have minutes */ )*60 + sec; /* finally seconds */ } - -EXPORT_SYMBOL(mktime); +EXPORT_SYMBOL(mktime64); /** * set_normalized_timespec - set timespec sec and nsec parts and normalize