From patchwork Tue Jan 20 16:21:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 43413 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 023572034D for ; Tue, 20 Jan 2015 16:23:48 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id f15sf6947734lbj.2 for ; Tue, 20 Jan 2015 08:23:46 -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=N5IZlOAA7X4KR67+t7PfFX1WTyQg7MaD87hVwHlPqdY=; b=EBC3XofP6Q3qcmgLPQXzfX+Y3QvBzx8qI0ZI7ZABdgfGVEYocGcjYcCMeGGjN4633q 6To0cymOP6zTBAJhyN8k/xSLsQISBhEcZ7PDvmf/APxVKJryPIwnUsUu4cMH03GztisZ F/c38b5tkgqvj97kcv+lY9ScmTninVVhWqf8FOxXaqhMpB7zM/lSo8oss9Kj713AAR11 YarEbzsmVibWmPWOChBUke3jLah7T/bDAFOS4mVu//K0hCxeZw6erFck1IdmtIY1shS0 jgir2mME6T+eLLvO0LprgORPZZSzzehzCfEijOu/p49ZmEDw+HfMx0fHa3gbM1b9OPj5 48BQ== X-Gm-Message-State: ALoCoQmd6ThetnZ5Kg2Nw3tob86ZNuA76PdWDuMZ17Hi0Ae+hoARYvpBSm4EGmNSCGIkUPlvFZ3t X-Received: by 10.180.92.66 with SMTP id ck2mr2759003wib.3.1421771026894; Tue, 20 Jan 2015 08:23:46 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.5 with SMTP id m5ls753639laj.71.gmail; Tue, 20 Jan 2015 08:23:46 -0800 (PST) X-Received: by 10.152.163.100 with SMTP id yh4mr12250224lab.98.1421771026642; Tue, 20 Jan 2015 08:23:46 -0800 (PST) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id ds5si15548380lbc.138.2015.01.20.08.23.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Jan 2015 08:23:46 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id gd6so11580870lab.4 for ; Tue, 20 Jan 2015 08:23:46 -0800 (PST) X-Received: by 10.112.41.234 with SMTP id i10mr39949500lbl.25.1421771026516; Tue, 20 Jan 2015 08:23:46 -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.9.200 with SMTP id c8csp1473455lbb; Tue, 20 Jan 2015 08:23:45 -0800 (PST) X-Received: by 10.70.37.166 with SMTP id z6mr44704918pdj.89.1421771024614; Tue, 20 Jan 2015 08:23:44 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hw8si4966695pbc.148.2015.01.20.08.23.43; Tue, 20 Jan 2015 08:23:44 -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 S1754198AbbATQXi (ORCPT + 28 others); Tue, 20 Jan 2015 11:23:38 -0500 Received: from mail-qc0-f177.google.com ([209.85.216.177]:51675 "EHLO mail-qc0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753252AbbATQWV (ORCPT ); Tue, 20 Jan 2015 11:22:21 -0500 Received: by mail-qc0-f177.google.com with SMTP id p6so6490106qcv.8 for ; Tue, 20 Jan 2015 08:22:20 -0800 (PST) X-Received: by 10.140.30.197 with SMTP id d63mr32957106qgd.13.1421770940360; Tue, 20 Jan 2015 08:22:20 -0800 (PST) Received: from ip-10-181-65-231.ec2.internal ([54.235.93.228]) by mx.google.com with ESMTPSA id o34sm15633515qge.29.2015.01.20.08.22.19 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Jan 2015 08:22:19 -0800 (PST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: rtc-linux@googlegroups.com, Thomas Gleixner , Alessandro Zummo , Richard Henderson , Uwe Kleine-Koenig , Linus Walleij , Fabio Estevam , John Stultz , Arnd Bergmann , Xunlei Pang Subject: [RFC PATCH v3 4/8] rtc/mc13xxx: Update driver to address y2038/y2106 issues Date: Tue, 20 Jan 2015 16:21:35 +0000 Message-Id: <1421770899-4136-5-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 2.2.1 In-Reply-To: <1421770899-4136-1-git-send-email-pang.xunlei@linaro.org> References: <1421770899-4136-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.45 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: , This driver has a number of y2038/y2106 issues. This patch resolves them by: - Replace rtc_time_to_tm() with rtc_time64_to_tm() - Change mc13xxx_rtc_set_mmss() to use rtc_class_ops's set_mmss64() After this patch, the driver should not have any remaining y2038/y2106 issues. Signed-off-by: Xunlei Pang --- drivers/rtc/rtc-mc13xxx.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c index 5bce904b..32df1d8 100644 --- a/drivers/rtc/rtc-mc13xxx.c +++ b/drivers/rtc/rtc-mc13xxx.c @@ -83,20 +83,19 @@ static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm) return ret; } while (days1 != days2); - rtc_time_to_tm(days1 * SEC_PER_DAY + seconds, tm); + rtc_time64_to_tm((time64_t)days1 * SEC_PER_DAY + seconds, tm); return rtc_valid_tm(tm); } -static int mc13xxx_rtc_set_mmss(struct device *dev, unsigned long secs) +static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs) { struct mc13xxx_rtc *priv = dev_get_drvdata(dev); unsigned int seconds, days; unsigned int alarmseconds; int ret; - seconds = secs % SEC_PER_DAY; - days = secs / SEC_PER_DAY; + days = div_s64_rem(secs, SEC_PER_DAY, &seconds); mc13xxx_lock(priv->mc13xxx); @@ -159,7 +158,7 @@ static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct mc13xxx_rtc *priv = dev_get_drvdata(dev); unsigned seconds, days; - unsigned long s1970; + time64_t s1970; int enabled, pending; int ret; @@ -189,10 +188,10 @@ out: alarm->enabled = enabled; alarm->pending = pending; - s1970 = days * SEC_PER_DAY + seconds; + s1970 = (time64_t)days * SEC_PER_DAY + seconds; - rtc_time_to_tm(s1970, &alarm->time); - dev_dbg(dev, "%s: %lu\n", __func__, s1970); + rtc_time64_to_tm(s1970, &alarm->time); + dev_dbg(dev, "%s: %lld\n", __func__, (long long)s1970); return 0; } @@ -200,8 +199,8 @@ out: static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct mc13xxx_rtc *priv = dev_get_drvdata(dev); - unsigned long s1970; - unsigned seconds, days; + time64_t s1970; + u32 seconds, days; int ret; mc13xxx_lock(priv->mc13xxx); @@ -215,20 +214,17 @@ static int mc13xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) if (unlikely(ret)) goto out; - ret = rtc_tm_to_time(&alarm->time, &s1970); - if (unlikely(ret)) - goto out; + s1970 = rtc_tm_to_time64(&alarm->time); - dev_dbg(dev, "%s: o%2.s %lu\n", __func__, alarm->enabled ? "n" : "ff", - s1970); + dev_dbg(dev, "%s: o%2.s %lld\n", __func__, alarm->enabled ? "n" : "ff", + (long long)s1970); ret = mc13xxx_rtc_irq_enable_unlocked(dev, alarm->enabled, MC13XXX_IRQ_TODA); if (unlikely(ret)) goto out; - seconds = s1970 % SEC_PER_DAY; - days = s1970 / SEC_PER_DAY; + days = div_s64_rem(s1970, SEC_PER_DAY, &seconds); ret = mc13xxx_reg_write(priv->mc13xxx, MC13XXX_RTCDAYA, days); if (unlikely(ret)) @@ -268,7 +264,7 @@ static irqreturn_t mc13xxx_rtc_update_handler(int irq, void *dev) static const struct rtc_class_ops mc13xxx_rtc_ops = { .read_time = mc13xxx_rtc_read_time, - .set_mmss = mc13xxx_rtc_set_mmss, + .set_mmss64 = mc13xxx_rtc_set_mmss, .read_alarm = mc13xxx_rtc_read_alarm, .set_alarm = mc13xxx_rtc_set_alarm, .alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable,