From patchwork Tue Jan 13 15:44:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 43063 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E9F1520DE8 for ; Tue, 13 Jan 2015 15:52:20 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf2373099eek.1 for ; Tue, 13 Jan 2015 07:52:20 -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=7+H9XwpmjBtZ2CPI+td3mciHCmriQgtcC7zmBKfzpIk=; b=GjgsN/UP8TaZxob6vN9vs2ZZwIKTeb4ZT1OMvGDDYFe145hmBnsGTkpsKgGrty5mHF hAeZY3Ia/8N4nCRjZR1CCGQKH4HghrtwFqsG3/xfs+Rw25HGP/evL3caLVcYV3r56ms0 bu4kxZd2vRpnXwC1cgYctlQ+mnq3M/bBUGSFlS7BZcy0sI4QnD83WJIhKrjVLN1IC60y MxPHEWTc/cdJDMfwoK8CjfDYdQv0GmSVC8v78WtCnWKp0FgURsYcKec8tg+Pu0qA1wIM PlzJ4Uq+Go4O0S2hqI5VlMYO3UrmRhUW26VxByM027PuUp/QHgZm5MLgu/mC40CUWMXO KioQ== X-Gm-Message-State: ALoCoQlGsYewXDMvVT5OC3J1qkOuufA3xstsYZK32BA2gsVOY205cQUFeZgvdn865MZUPCyWCPDs X-Received: by 10.113.5.170 with SMTP id cn10mr142723lbd.21.1421164339543; Tue, 13 Jan 2015 07:52:19 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.229 with SMTP id 5ls10042lap.55.gmail; Tue, 13 Jan 2015 07:52:19 -0800 (PST) X-Received: by 10.152.18.225 with SMTP id z1mr43362266lad.0.1421164339236; Tue, 13 Jan 2015 07:52:19 -0800 (PST) Received: from mail-la0-x22b.google.com (mail-la0-x22b.google.com. [2a00:1450:4010:c03::22b]) by mx.google.com with ESMTPS id z6si3321097laj.17.2015.01.13.07.52.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 Jan 2015 07:52:19 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22b as permitted sender) client-ip=2a00:1450:4010:c03::22b; Received: by mail-la0-f43.google.com with SMTP id s18so3357926lam.2 for ; Tue, 13 Jan 2015 07:52:19 -0800 (PST) X-Received: by 10.152.27.8 with SMTP id p8mr43397233lag.69.1421164339117; Tue, 13 Jan 2015 07:52:19 -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 c8csp1422497lbb; Tue, 13 Jan 2015 07:52:18 -0800 (PST) X-Received: by 10.70.50.102 with SMTP id b6mr53438114pdo.38.1421164337243; Tue, 13 Jan 2015 07:52:17 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ow1si27399878pbb.118.2015.01.13.07.52.16; Tue, 13 Jan 2015 07:52:17 -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 S1753204AbbAMPva (ORCPT + 27 others); Tue, 13 Jan 2015 10:51:30 -0500 Received: from m15-111.126.com ([220.181.15.111]:38549 "EHLO m15-111.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752501AbbAMPv3 (ORCPT ); Tue, 13 Jan 2015 10:51:29 -0500 Received: from vptest-PC.zte.com.cn (unknown [182.149.91.53]) by smtp1 (Coremail) with SMTP id C8mowEAZEUVxPbVUBIRpDg--.692S8; Tue, 13 Jan 2015 23:44:59 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org, John Stultz , Arnd Bergmann Cc: rtc-linux@googlegroups.com, Thomas Gleixner , Alessandro Zummo , Xunlei Pang Subject: [RFC PATCH v2 5/9] rtc/mc13xxx: Update driver to address y2038/y2106 issues Date: Tue, 13 Jan 2015 23:44:53 +0800 Message-Id: <1421163897-8020-6-git-send-email-xlpang@126.com> X-Mailer: git-send-email 2.0.4 In-Reply-To: <1421163897-8020-1-git-send-email-xlpang@126.com> References: <1421163897-8020-1-git-send-email-xlpang@126.com> X-CM-TRANSID: C8mowEAZEUVxPbVUBIRpDg--.692S8 X-Coremail-Antispam: 1Uf129KBjvJXoWxAF15Ary3JF47GF4DCF1rWFg_yoW5KrWUpF 4Syas8Jr40qF9xWw1kKFyDCFyFy3yktFW8Gan7K34v9w13Ja4DKF18ur1jga4rKa95Gr4x ua1UXF15u3WUCa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jd_-9UUUUU= X-Originating-IP: [182.149.91.53] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbiXB2Av1R0UfuaHAAAsy Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: xlpang@126.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22b as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@; dmarc=fail (p=NONE dis=NONE) header.from=126.com 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: , From: Xunlei Pang 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,