From patchwork Tue Nov 18 11:15:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 41010 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AB64E241C9 for ; Tue, 18 Nov 2014 11:20:43 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id ex7sf4439790wid.3 for ; Tue, 18 Nov 2014 03:20:43 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=oyQPCKIZR6N/hsFSGJym0qePsHiGbBqAF98MMeKikD0=; b=JjdiOPkGj5GL3c/d20Xv6VERgxzvsxtXat9JvHfbQhW1V6pLLiGV4P46fy3jF1aApP GmBCAcYTlTRTHe5ro/rTJejZdGgOoZPBzadXDUjjpl47CqvyK4QX0S6Hubzp2pwqTNmF L1J/c7b+Qput91ckoaesFukp6CWOvg5ErJyg8Jyy5YDA5KfZcggipwag3aIQ2td+XN3h inWZJzWWF4LIfZw4enAR/zB5/h5VBOLjVuLGLLBstJlms83p27KnMRoGu46M/BTshAda 8ceB0Omm1CJQVHzbqt1uNzkWhst/26MAmlUZntVI6BWXholBy5Gf4mcM8NMfGWYZqi49 6DBA== X-Gm-Message-State: ALoCoQlJPg3JzCG1uY/OxlXPu6B6/EW0HCU7ndQqN6N2ecQxQU7w+si0MwI5cH3UqcxRMsKJf9uC X-Received: by 10.112.89.195 with SMTP id bq3mr2805755lbb.9.1416309642954; Tue, 18 Nov 2014 03:20:42 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.129 with SMTP id t1ls1397713lag.53.gmail; Tue, 18 Nov 2014 03:20:42 -0800 (PST) X-Received: by 10.152.1.130 with SMTP id 2mr17988371lam.89.1416309642554; Tue, 18 Nov 2014 03:20:42 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id k17si55270364laa.67.2014.11.18.03.20.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 03:20:42 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id b6so17651003lbj.30 for ; Tue, 18 Nov 2014 03:20:42 -0800 (PST) X-Received: by 10.112.235.196 with SMTP id uo4mr34849705lbc.66.1416309642462; Tue, 18 Nov 2014 03:20:42 -0800 (PST) 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.184.201 with SMTP id ew9csp1310489lbc; Tue, 18 Nov 2014 03:20:41 -0800 (PST) X-Received: by 10.66.249.163 with SMTP id yv3mr35899204pac.77.1416309640763; Tue, 18 Nov 2014 03:20:40 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mn10si10132601pbc.208.2014.11.18.03.20.39 for ; Tue, 18 Nov 2014 03:20:40 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754030AbaKRLUb (ORCPT + 26 others); Tue, 18 Nov 2014 06:20:31 -0500 Received: from mail-pd0-f171.google.com ([209.85.192.171]:33143 "EHLO mail-pd0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753169AbaKRLUY (ORCPT ); Tue, 18 Nov 2014 06:20:24 -0500 Received: by mail-pd0-f171.google.com with SMTP id v10so42591pde.2 for ; Tue, 18 Nov 2014 03:20:24 -0800 (PST) X-Received: by 10.68.174.131 with SMTP id bs3mr36091520pbc.20.1416309624083; Tue, 18 Nov 2014 03:20:24 -0800 (PST) Received: from wangdeqiang.com ([210.21.223.3]) by mx.google.com with ESMTPSA id l13sm7556923pbq.40.2014.11.18.03.20.19 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 03:20:23 -0800 (PST) From: "pang.xunlei" To: linux-kernel@vger.kernel.org Cc: rtc-linux@googlegroups.com, Thomas Gleixner , Alessandro Zummo , John Stultz , Arnd Bergmann , "pang.xunlei" Subject: [RFC PATCH v3 3/5] time: Provide y2038 safe mktime() replacement Date: Tue, 18 Nov 2014 19:15:18 +0800 Message-Id: <1416309320-7498-4-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1416309320-7498-1-git-send-email-pang.xunlei@linaro.org> References: <1416309320-7498-1-git-send-email-pang.xunlei@linaro.org> 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: pang.xunlei@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.171 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: , 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. Signed-off-by: pang.xunlei --- 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