From patchwork Fri Nov 21 19:44:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 41362 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 146102452C for ; Fri, 21 Nov 2014 19:44:52 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id u10sf1232432lbd.10 for ; Fri, 21 Nov 2014 11:44:51 -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=hFFzhkimPKbkFmb+lypdEMgprc+IWtnyJroCYyN+7Lg=; b=ERPNB+iotXQts/TXtMymwiblAh/ULViLWIFkfngVbymYJZxrk+PZOKtolarN+Hb/+R ZYaQoUrmsMUq+ILrJ2aLVM6DiCekpXO1TQASOnzQo8TH9zmjm0fO7xg9lsyznDQMlizr IrnfkH3MOwR76jRY+dwL5QI0UDxyrrDFWGNayaYybpVShGtGdwWM4wyQpw9fn0r4uJCa gU9BgVIrrTkCGAjE/AXaKCNh+5E3BRjZzzvMaoVYvhO3111AndlUA44x5QXT4/p8BxJY tMH9QqBA3vuvmyFSc6aQ2EVau5AyZk/Mj9S1gjYa2uLNGwxZxHmt5jco8hFIvZf3z6QQ xKcQ== X-Gm-Message-State: ALoCoQms+PPbTflQIFjbOTmA8ZF/x+rj4MVoyTHnx5hHrDWJMTS8dUv/edG9oZEp154zNbwfBrDA X-Received: by 10.112.48.6 with SMTP id h6mr1386061lbn.19.1416599091077; Fri, 21 Nov 2014 11:44:51 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.71 with SMTP id da7ls250118lad.31.gmail; Fri, 21 Nov 2014 11:44:50 -0800 (PST) X-Received: by 10.152.21.135 with SMTP id v7mr7414660lae.65.1416599090606; Fri, 21 Nov 2014 11:44:50 -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 ay11si6956531lab.132.2014.11.21.11.44.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 11:44:50 -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 f15so3439227lbj.23 for ; Fri, 21 Nov 2014 11:44:50 -0800 (PST) X-Received: by 10.152.37.69 with SMTP id w5mr7139644laj.67.1416599090508; Fri, 21 Nov 2014 11:44:50 -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 ew9csp153753lbc; Fri, 21 Nov 2014 11:44:49 -0800 (PST) X-Received: by 10.68.98.131 with SMTP id ei3mr10078535pbb.127.1416599086870; Fri, 21 Nov 2014 11:44:46 -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 ga4si10107077pbb.176.2014.11.21.11.44.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 11:44:46 -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 kq14so5439027pab.26 for ; Fri, 21 Nov 2014 11:44:46 -0800 (PST) X-Received: by 10.66.235.74 with SMTP id uk10mr10745259pac.16.1416599086155; Fri, 21 Nov 2014 11:44:46 -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.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Nov 2014 11:44:45 -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 10/12] rtc/lib: Provide y2038 safe rtc_tm_to_time()/rtc_time_to_tm() replacement Date: Fri, 21 Nov 2014 11:44:16 -0800 Message-Id: <1416599058-13836-11-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.178 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 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. 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 --- 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