From patchwork Tue Jan 20 16:21:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 431154 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-qa0-x23c.google.com (mail-qa0-x23c.google.com [IPv6:2607:f8b0:400d:c00::23c]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 56F551402C9 for ; Wed, 21 Jan 2015 03:22:24 +1100 (AEDT) Received: by mail-qa0-f60.google.com with SMTP id w8sf5921984qac.5 for ; Tue, 20 Jan 2015 08:22:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :reply-to:content-type:precedence:mailing-list:list-id:list-post :list-help:list-archive:sender:list-subscribe:list-unsubscribe; bh=Lo09uooLT12yLqOKxqg6DuosuYMsnifOxuYklaNW1sI=; b=ev4lWiSjnQndu35rix0m7hTQwjgjXda2rWMRuI5/tqOh7LU4pANeQEyU4bxBts9iQ5 HfmgcxUC+bTWJwUhJvo4NdS9xKk91v6rusP6i+keXTI+lR5w7ZtEmFx23CDUk6puNA40 gacVIy6B0buz8cuzgHFxDkWgppAMwsNNQT/Lmb1L9qkt3XQJv7WyoaEhEGn8IVee7AO2 nz6BvEp1WdusGW4egQkLg7trnY8ZLhZy8ZSh+2gp62joPrG6VEL165j8kx5ZMD98WA+r m0gHgc/TDTk9co/DfodvUBdB5l6L/LWoQom9BDnA+jeMH9njC6pGhNPHspmD1RoClDWX 69Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:reply-to:content-type:precedence :mailing-list:list-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe; bh=Lo09uooLT12yLqOKxqg6DuosuYMsnifOxuYklaNW1sI=; b=Ok+ZRIs5iMhnqY1SVR4OYvUSta+mqcC22AVAQwNg7IA2Nx/gsHvJO58cR/VnBcOCjX 1UkHICmEmIVkzRVIIPDTa9sk8FfbO5J5oBdJqUf4+OpflKir2m+Bq1Zzzi4YskVrcVid YnJ1Vf41gMvJn7HTa+XBgq2ms1rJ5YM9BqcbthoOo637Te6A+Uwrbq6doqSoxaFoGCrJ gL7sr74M+1AjEJyRZeoIgNDRh2/CVMl6C1P+cURR15BXHhE0xaZJVOQKf/r+L0BhET39 gIou4B/pSRcToPRVsb48j1I6I2jT8zPDPKNGAXbD1M5w7UGZ15cPvhGG1DapLmqyoRLf fnSw== X-Received: by 10.140.97.200 with SMTP id m66mr306qge.42.1421770942547; Tue, 20 Jan 2015 08:22:22 -0800 (PST) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.140.104.75 with SMTP id z69ls993509qge.33.gmail; Tue, 20 Jan 2015 08:22:22 -0800 (PST) X-Received: by 10.236.70.100 with SMTP id o64mr31027583yhd.9.1421770942195; Tue, 20 Jan 2015 08:22:22 -0800 (PST) Received: from mail-qc0-f181.google.com (mail-qc0-f181.google.com. [209.85.216.181]) by gmr-mx.google.com with ESMTPS id v10si94597qcf.3.2015.01.20.08.22.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Jan 2015 08:22:22 -0800 (PST) Received-SPF: pass (google.com: domain of pang.xunlei@linaro.org designates 209.85.216.181 as permitted sender) client-ip=209.85.216.181; Received: by mail-qc0-f181.google.com with SMTP id l6so22920952qcy.12 for ; Tue, 20 Jan 2015 08:22:22 -0800 (PST) X-Gm-Message-State: ALoCoQmB+q2gEoUHV171Aj03uzfH1IrwjHsBX15utOMt40hNzB7p4Z/WZz37G9oWnjP+0HCo4nv2 X-Received: by 10.140.109.164 with SMTP id l33mr42465280qgf.91.1421770942066; Tue, 20 Jan 2015 08:22:22 -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.21 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Jan 2015 08:22:21 -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: [rtc-linux] [RFC PATCH v3 6/8] rtc/mxc: Convert get_alarm_or_time()/set_alarm_or_time() to use time64_t Date: Tue, 20 Jan 2015 16:21:37 +0000 Message-Id: <1421770899-4136-7-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> X-Original-Sender: pang.xunlei@linaro.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of pang.xunlei@linaro.org designates 209.85.216.181 as permitted sender) smtp.mail=pang.xunlei@linaro.org Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , We want to convert mxc_rtc_set_mmss() to use rtc_class_ops's set_mmss64(), but it uses get_alarm_or_time()/set_alarm_or_time() internal interfaces which are y2038 unsafe. So here as a separate patch, it converts these two internal interfaces of "mxc" to use safe time64_t to make some preparations. Signed-off-by: Xunlei Pang --- drivers/rtc/rtc-mxc.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c index a7b218f..83cba23 100644 --- a/drivers/rtc/rtc-mxc.c +++ b/drivers/rtc/rtc-mxc.c @@ -106,7 +106,7 @@ static inline int is_imx1_rtc(struct rtc_plat_data *data) * This function is used to obtain the RTC time or the alarm value in * second. */ -static u32 get_alarm_or_time(struct device *dev, int time_alarm) +static time64_t get_alarm_or_time(struct device *dev, int time_alarm) { struct platform_device *pdev = to_platform_device(dev); struct rtc_plat_data *pdata = platform_get_drvdata(pdev); @@ -129,29 +129,28 @@ static u32 get_alarm_or_time(struct device *dev, int time_alarm) hr = hr_min >> 8; min = hr_min & 0xff; - return (((day * 24 + hr) * 60) + min) * 60 + sec; + return ((((time64_t)day * 24 + hr) * 60) + min) * 60 + sec; } /* * This function sets the RTC alarm value or the time value. */ -static void set_alarm_or_time(struct device *dev, int time_alarm, u32 time) +static void set_alarm_or_time(struct device *dev, int time_alarm, time64_t time) { - u32 day, hr, min, sec, temp; + u32 tod, day, hr, min, sec, temp; struct platform_device *pdev = to_platform_device(dev); struct rtc_plat_data *pdata = platform_get_drvdata(pdev); void __iomem *ioaddr = pdata->ioaddr; - day = time / 86400; - time -= day * 86400; + day = div_s64_rem(time, 86400, &tod); /* time is within a day now */ - hr = time / 3600; - time -= hr * 3600; + hr = tod / 3600; + tod -= hr * 3600; /* time is within an hour now */ - min = time / 60; - sec = time - min * 60; + min = tod / 60; + sec = tod - min * 60; temp = (hr << 8) + min; @@ -175,12 +174,12 @@ static void set_alarm_or_time(struct device *dev, int time_alarm, u32 time) */ static void rtc_update_alarm(struct device *dev, struct rtc_time *alrm) { - unsigned long time; + time64_t time; struct platform_device *pdev = to_platform_device(dev); struct rtc_plat_data *pdata = platform_get_drvdata(pdev); void __iomem *ioaddr = pdata->ioaddr; - rtc_tm_to_time(alrm, &time); + time = rtc_tm_to_time64(alrm); /* clear all the interrupt status bits */ writew(readw(ioaddr + RTC_RTCISR), ioaddr + RTC_RTCISR); @@ -272,14 +271,14 @@ static int mxc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) */ static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm) { - u32 val; + time64_t val; /* Avoid roll-over from reading the different registers */ do { val = get_alarm_or_time(dev, MXC_RTC_TIME); } while (val != get_alarm_or_time(dev, MXC_RTC_TIME)); - rtc_time_to_tm(val, tm); + rtc_time64_to_tm(val, tm); return 0; } @@ -322,7 +321,7 @@ static int mxc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) struct rtc_plat_data *pdata = platform_get_drvdata(pdev); void __iomem *ioaddr = pdata->ioaddr; - rtc_time_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); + rtc_time64_to_tm(get_alarm_or_time(dev, MXC_RTC_ALARM), &alrm->time); alrm->pending = ((readw(ioaddr + RTC_RTCISR) & RTC_ALM_BIT)) ? 1 : 0; return 0;