From patchwork Thu Oct 30 11:15:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 39818 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 ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 984B1202FE for ; Thu, 30 Oct 2014 11:17:18 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id b6sf1446032lbj.4 for ; Thu, 30 Oct 2014 04:17:17 -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=CKuqU7WMDN9q9Xqe0pa9ZBAtPaDvTuXcW2ppvCHepSg=; b=HuQxZ+f2tgzIbTwzcnaqKmfcy+PNcteAsk7fajcbfAmXfwsfM4B/QQDZatDSUxH3Yw eu/nU2t624PXkuT/495fEF5Y/1fE1vmAY1fDYuSKb5Fte6UlWaIA10AdKFGO86qzARwb vicdEd4BY9w1rkTbhCRnKMtzn9XBsIgKpKuWAk0x58fQR4BudRCk21lZJIm7R/VA446o oyonbDKomGLxI6BFIYsQxVMRN3dwhDmOH36FZ+xPSLKd2XsnqSJTOd1OtB7zhuorB5N1 X3AHOUJ1k64SRrEOo+Hgn2RhJ5BEDexjYSVMRhsQEzIK4BY6/4X2Z1PB7fXW1caKngRm KHpQ== X-Gm-Message-State: ALoCoQkePmbJfQr7FNPXenXOI3/ZouZqQXYA/uUrm8HpxwlX7dMoCLcmDNL0Cm8EcTzC5SmThuW+ X-Received: by 10.112.38.101 with SMTP id f5mr2811457lbk.7.1414667837099; Thu, 30 Oct 2014 04:17:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.4 with SMTP id x4ls326347lag.42.gmail; Thu, 30 Oct 2014 04:17:16 -0700 (PDT) X-Received: by 10.153.7.107 with SMTP id db11mr18186803lad.35.1414667836919; Thu, 30 Oct 2014 04:17:16 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id w5si11500530lae.80.2014.10.30.04.17.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Oct 2014 04:17:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id gq15so4250234lab.1 for ; Thu, 30 Oct 2014 04:17:16 -0700 (PDT) X-Received: by 10.153.8.164 with SMTP id dl4mr18121119lad.29.1414667836834; Thu, 30 Oct 2014 04:17:16 -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.84.229 with SMTP id c5csp22348lbz; Thu, 30 Oct 2014 04:17:15 -0700 (PDT) X-Received: by 10.70.54.227 with SMTP id m3mr16987113pdp.66.1414667834456; Thu, 30 Oct 2014 04:17:14 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ao2si6410123pad.52.2014.10.30.04.17.13 for ; Thu, 30 Oct 2014 04:17:14 -0700 (PDT) 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 S1759349AbaJ3LRK (ORCPT + 26 others); Thu, 30 Oct 2014 07:17:10 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:35231 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759108AbaJ3LRF (ORCPT ); Thu, 30 Oct 2014 07:17:05 -0400 Received: by mail-pa0-f44.google.com with SMTP id bj1so5275173pad.31 for ; Thu, 30 Oct 2014 04:17:03 -0700 (PDT) X-Received: by 10.70.48.202 with SMTP id o10mr16682859pdn.63.1414667823923; Thu, 30 Oct 2014 04:17:03 -0700 (PDT) Received: from wangdeqiang.com ([210.21.227.66]) by mx.google.com with ESMTPSA id i10sm6874826pdr.21.2014.10.30.04.16.58 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Oct 2014 04:17:03 -0700 (PDT) From: "pang.xunlei" To: linux-kernel@vger.kernel.org Cc: rtc-linux@googlegroups.com, xen-devel@lists.xenproject.org, John Stultz , Thomas Gleixner , Alessandro Zummo , Stefano Stabellini , "pang.xunlei" Subject: [RFC PATCH v2 03/11] time: Add rtc_tm_to_time64() safe version(using time64_t) Date: Thu, 30 Oct 2014 19:15:37 +0800 Message-Id: <1414667745-7703-4-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1414667745-7703-1-git-send-email-pang.xunlei@linaro.org> References: <1414667745-7703-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.215.42 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 2038 saftey for in-kernel uses, this patch adds safe rtc_tm_to_time64() using time64_t. After this patch, rtc_tm_to_time() should be replaced by rtc_tm_to_time64() one by one. Eventually, rtc_tm_to_time() will be removed from the kernel when it has no users. Signed-off-by: pang.xunlei --- drivers/rtc/rtc-lib.c | 15 ++++++++++++++- include/linux/rtc.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index c4cf057..6948cbd 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c @@ -110,10 +110,23 @@ EXPORT_SYMBOL(rtc_valid_tm); /* * Convert Gregorian date to seconds since 01-01-1970 00:00:00. + * Safe version for 2038 safety. + */ +int rtc_tm_to_time64(struct rtc_time *tm, time64_t *time) +{ + *time = 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_time64); + +/* + * Convert Gregorian date to seconds since 01-01-1970 00:00:00. + * TODO: [2038 safety] should be replaced by rtc_tm_to_time64. */ int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time) { - *time = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, + *time = (unsigned long) mktime64(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); return 0; } diff --git a/include/linux/rtc.h b/include/linux/rtc.h index c2c2897..2a6a9ce 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -19,6 +19,7 @@ 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_time64(struct rtc_time *tm, time64_t *time); 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); ktime_t rtc_tm_to_ktime(struct rtc_time tm);