From patchwork Tue Nov 18 11:15:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 41012 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 58BB1241C9 for ; Tue, 18 Nov 2014 11:21:03 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id c13sf1920718eek.10 for ; Tue, 18 Nov 2014 03:21:02 -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=6sHZIvqUK8PAgljXsHcCJ8NlQHcadU+ShaaaJjGFbW4=; b=Ka/Rjn1xbbXBm+cdqCRJ9yqW8gtfigaUMxZsIBewaW09NoCPAKKKREnPAywc/87vNr oRMQR6AnmaSGesxCbEwxWBITlYfjuyw7YVmqp7WwhS64ZWqOO5AISdk8d8suw0lj/UoS XI7MfYN86f4wUgZFIi/NLFH2lIIHQTjDCehNt9ehQrLeg+LXoB68/Y1HJ/rd3CA4hAGF HFGKNrTx5R6F01z9QsKwfkjblldlrFoPRw1/MBQRsFmJpycV2jOm6/fzIeoB2tCOmJSW omvARwxMaRW3fW4bwq/5ZNGVnvFDKI/Mzfy8gSUBWCN1ill7tHwXezfP0hC1+4a7XW/H 3Ncw== X-Gm-Message-State: ALoCoQl/ez3PDYxOZ/kaparEK+6eS7FhbjtmjM19VvOGtmDHYeayMkp8eiWoT2+mBKbEvnudTzE6 X-Received: by 10.181.13.80 with SMTP id ew16mr5564341wid.4.1416309662366; Tue, 18 Nov 2014 03:21:02 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.40 with SMTP id 8ls1331855lar.61.gmail; Tue, 18 Nov 2014 03:21:02 -0800 (PST) X-Received: by 10.152.7.229 with SMTP id m5mr35539102laa.32.1416309662163; Tue, 18 Nov 2014 03:21:02 -0800 (PST) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id wr5si55406958lac.11.2014.11.18.03.21.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 03:21:02 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id f15so19282070lbj.37 for ; Tue, 18 Nov 2014 03:21:02 -0800 (PST) X-Received: by 10.152.37.69 with SMTP id w5mr34697386laj.67.1416309662039; Tue, 18 Nov 2014 03:21:02 -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 ew9csp1310527lbc; Tue, 18 Nov 2014 03:21:00 -0800 (PST) X-Received: by 10.68.225.162 with SMTP id rl2mr10867198pbc.129.1416309660209; Tue, 18 Nov 2014 03:21:00 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pj10si36065019pdb.241.2014.11.18.03.20.59 for ; Tue, 18 Nov 2014 03:21:00 -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 S1754129AbaKRLU6 (ORCPT + 26 others); Tue, 18 Nov 2014 06:20:58 -0500 Received: from mail-pd0-f176.google.com ([209.85.192.176]:60709 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752917AbaKRLU3 (ORCPT ); Tue, 18 Nov 2014 06:20:29 -0500 Received: by mail-pd0-f176.google.com with SMTP id y10so3863801pdj.21 for ; Tue, 18 Nov 2014 03:20:28 -0800 (PST) X-Received: by 10.70.55.40 with SMTP id o8mr35416689pdp.87.1416309628822; Tue, 18 Nov 2014 03:20:28 -0800 (PST) Received: from wangdeqiang.com ([210.21.223.3]) by mx.google.com with ESMTPSA id l13sm7556923pbq.40.2014.11.18.03.20.24 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 03:20:28 -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 4/5] rtc/lib: Provide y2038 safe rtc_tm_to_time()/rtc_time_to_tm() replacement Date: Tue, 18 Nov 2014 19:15:19 +0800 Message-Id: <1416309320-7498-5-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.178 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 rtc_tm_to_time64()/rtc_time64_to_tm() respectively using time64_t. After this patch, rtc_tm_to_time() is deprecated and all its call sites will be fixed using corresponding safe versions, it can be removed when having no users. Also change rtc_tm_to_time64() to return time64_t directly instead of just as a parameter like rtc_tm_to_time() does. After this patch, rtc_time_to_tm() is deprecated and all its call sites will be fixed using corresponding safe versions, it can be removed when having no users. In addition, change rtc_tm_to_ktime() and rtc_ktime_to_tm() to use the safe version in passing. Signed-off-by: pang.xunlei --- drivers/rtc/rtc-lib.c | 38 ++++++++++++++++++++------------------ include/linux/rtc.h | 21 +++++++++++++++++++-- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index c4cf057..e6bfb9c 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c @@ -45,16 +45,20 @@ int rtc_year_days(unsigned int day, unsigned int month, unsigned int year) } EXPORT_SYMBOL(rtc_year_days); + /* + * rtc_time_to_tm64 - Converts time64_t to rtc_time. * Convert seconds since 01-01-1970 00:00:00 to Gregorian date. */ -void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) +void rtc_time64_to_tm(time64_t time, struct rtc_time *tm) { unsigned int month, year; + unsigned long secs; int days; - days = time / 86400; - time -= (unsigned int) days * 86400; + /* time must be positive */ + days = div_s64(time, 86400); + secs = time - (unsigned int) days * 86400; /* day of the week, 1970-01-01 was a Thursday */ tm->tm_wday = (days + 4) % 7; @@ -81,14 +85,14 @@ void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) tm->tm_mon = month; tm->tm_mday = days + 1; - tm->tm_hour = time / 3600; - time -= tm->tm_hour * 3600; - tm->tm_min = time / 60; - tm->tm_sec = time - tm->tm_min * 60; + tm->tm_hour = secs / 3600; + secs -= tm->tm_hour * 3600; + tm->tm_min = secs / 60; + tm->tm_sec = secs - tm->tm_min * 60; tm->tm_isdst = 0; } -EXPORT_SYMBOL(rtc_time_to_tm); +EXPORT_SYMBOL(rtc_time64_to_tm); /* * Does the rtc_time represent a valid date/time? @@ -109,24 +113,22 @@ int rtc_valid_tm(struct rtc_time *tm) EXPORT_SYMBOL(rtc_valid_tm); /* + * rtc_tm_to_time64 - Converts rtc_time to time64_t. * Convert Gregorian date to seconds since 01-01-1970 00:00:00. */ -int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time) +time64_t rtc_tm_to_time64(struct rtc_time *tm) { - *time = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, + return mktime64(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); - return 0; } -EXPORT_SYMBOL(rtc_tm_to_time); +EXPORT_SYMBOL(rtc_tm_to_time64); /* * Convert rtc_time to ktime */ ktime_t rtc_tm_to_ktime(struct rtc_time tm) { - time_t time; - rtc_tm_to_time(&tm, &time); - return ktime_set(time, 0); + return ktime_set(rtc_tm_to_time64(&tm), 0); } EXPORT_SYMBOL_GPL(rtc_tm_to_ktime); @@ -135,14 +137,14 @@ EXPORT_SYMBOL_GPL(rtc_tm_to_ktime); */ struct rtc_time rtc_ktime_to_tm(ktime_t kt) { - struct timespec ts; + struct timespec64 ts; struct rtc_time ret; - ts = ktime_to_timespec(kt); + ts = ktime_to_timespec64(kt); /* Round up any ns */ if (ts.tv_nsec) ts.tv_sec++; - rtc_time_to_tm(ts.tv_sec, &ret); + rtc_time64_to_tm(ts.tv_sec, &ret); return ret; } EXPORT_SYMBOL_GPL(rtc_ktime_to_tm); diff --git a/include/linux/rtc.h b/include/linux/rtc.h index c2c2897..6d6be09 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -19,11 +19,28 @@ extern int rtc_month_days(unsigned int month, unsigned int year); extern int rtc_year_days(unsigned int day, unsigned int month, unsigned int year); extern int rtc_valid_tm(struct rtc_time *tm); -extern int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time); -extern void rtc_time_to_tm(unsigned long time, struct rtc_time *tm); +extern time64_t rtc_tm_to_time64(struct rtc_time *tm); +extern void rtc_time64_to_tm(time64_t time, struct rtc_time *tm); ktime_t rtc_tm_to_ktime(struct rtc_time tm); struct rtc_time rtc_ktime_to_tm(ktime_t kt); +/** + * Deprecated. Use rtc_time64_to_tm(). + */ +static inline void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) +{ + rtc_time64_to_tm(time, tm); +} + +/** + * Deprecated. Use rtc_tm_to_time64(). + */ +static inline int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time) +{ + *time = rtc_tm_to_time64(tm); + + return 0; +} #include #include