From patchwork Fri Apr 20 16:14:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 902027 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40SLZ16DpZz9ry1 for ; Sat, 21 Apr 2018 02:15:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751876AbeDTQOx (ORCPT ); Fri, 20 Apr 2018 12:14:53 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:55201 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750858AbeDTQOw (ORCPT ); Fri, 20 Apr 2018 12:14:52 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue003 [212.227.15.129]) with ESMTPA (Nemesis) id 0LuYSK-1eRniN2ZUW-00zmyA; Fri, 20 Apr 2018 18:14:35 +0200 From: Arnd Bergmann To: Alessandro Zummo , Alexandre Belloni Cc: y2038@lists.linaro.org, Arnd Bergmann , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] rtc: vr41xx: remove mktime usage Date: Fri, 20 Apr 2018 18:14:24 +0200 Message-Id: <20180420161433.3721192-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K1:5q6Yn/6t1PHM/iTwtOaUQDAOWGhqGQWn6ZhUBQMPfwOfzH+FHzT lPcDQWyLVkYwosho7qesbDYm9bKzB8SEehzgf7dFfSdhlCMVzD+M6V+OSVuf3PyAXzHOBf0 JUciYlMbFP4xPEvDvkkKr2m7SIyaLtodIGHfERJe2+ascePIaow3A6krgqcx/AuCdjwkJMy xfAXAgLzuw317DAFfRjOQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:g6+nH7Yf/T0=:uwuoSN6lV6R9JG4aoWip+T RGzfW6EpOXgfsFg6v7VpSuCFhlBRXu/VsUz6YKeGu7QByI9QzSOeL4o7803I1ZTDWBLrjzz+x Fh4Zdwqr0XI5sdDgCHdq/DJyWYPBkgh0mFgRHS40tHREkjr75yHNqLPDvSjVxxcPmMLv/LWtv a4U5UCDPojT78iz/cMhGMW/sNV5VMpS718gh3Uxh/XdmxEqCmpEq36yQQwX/DaZM6YREoUplj d8RljjZv9NxQZyve5z+q2xc+V0LVJ0i8sauCbDYDnA3g6GW1Cwso8ekGRyReu7OEnoxvypcCI ooz+wpF8KqS3eDYbTHiD9un0vTAezeYQpUeuSQiUA8oSCojUW8LFVaMToWUi0sPC4metPttRx W0Xf7GZP0YdzCspwm7GK2OcvLKI0We6QvoJoOZgzFZPCdprP9MySg2WMctzjjt6WWjchdfKm9 H7TiK5pNNs+PcQthIFeCRZESlUkVtXjn5hr9LWQ9SzP+w3indY1xE5BFgp9LB4QWirGGKOTJo 18N1fWPS5mG1qpwEtMZoZYlNPeTRTadT9TzcvZtMGc+faxoMmF0/lkcVPqC9RdsiYkU7VPu8Y FGKSOKun2hQ2rp98I/Q1Lo7xZHr8CjI6kyaiMj4Sh4eZzsHn3Uq8nSiUfPkrzd3zWXKgJMXIh 15kTswAAZEnb5PxeYC5xL+1hRNriDOddZSvkBeAWhSnoJu9O56TwmanPZXDCMYmjJ3OI915kh RuzQgBlSNajILJLQgLdNpGZDWEahtedKtMlbVA== Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org This driver uses mktime() and rtc_time_to_tm() to convert between time values. This works fine on 64-bit kernels over the whole supported range, and the vr41xx chip is a 64-bit MIPS implementation, but it is inconsistent because it doesn't do the same thing on 32-bit kernels that overflow in 2106 or 2038. Changing it to use mktime64/rtc_time64_to_tm() should have no visible impact on vr41xx but gets us closer to removing the 32-bit interfaces. Signed-off-by: Arnd Bergmann --- drivers/rtc/rtc-vr41xx.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c index 7ce22967fd16..480cffe8d321 100644 --- a/drivers/rtc/rtc-vr41xx.c +++ b/drivers/rtc/rtc-vr41xx.c @@ -88,7 +88,7 @@ static unsigned int alarm_enabled; static int aie_irq; static int pie_irq; -static inline unsigned long read_elapsed_second(void) +static inline time64_t read_elapsed_second(void) { unsigned long first_low, first_mid, first_high; @@ -105,10 +105,10 @@ static inline unsigned long read_elapsed_second(void) } while (first_low != second_low || first_mid != second_mid || first_high != second_high); - return (first_high << 17) | (first_mid << 1) | (first_low >> 15); + return ((u64)first_high << 17) | (first_mid << 1) | (first_low >> 15); } -static inline void write_elapsed_second(unsigned long sec) +static inline void write_elapsed_second(time64_t sec) { spin_lock_irq(&rtc_lock); @@ -121,22 +121,22 @@ static inline void write_elapsed_second(unsigned long sec) static int vr41xx_rtc_read_time(struct device *dev, struct rtc_time *time) { - unsigned long epoch_sec, elapsed_sec; + time64_t epoch_sec, elapsed_sec; - epoch_sec = mktime(epoch, 1, 1, 0, 0, 0); + epoch_sec = mktime64(epoch, 1, 1, 0, 0, 0); elapsed_sec = read_elapsed_second(); - rtc_time_to_tm(epoch_sec + elapsed_sec, time); + rtc_time64_to_tm(epoch_sec + elapsed_sec, time); return 0; } static int vr41xx_rtc_set_time(struct device *dev, struct rtc_time *time) { - unsigned long epoch_sec, current_sec; + time64_t epoch_sec, current_sec; - epoch_sec = mktime(epoch, 1, 1, 0, 0, 0); - current_sec = mktime(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, + epoch_sec = mktime64(epoch, 1, 1, 0, 0, 0); + current_sec = mktime64(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, time->tm_hour, time->tm_min, time->tm_sec); write_elapsed_second(current_sec - epoch_sec); @@ -165,11 +165,11 @@ static int vr41xx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) static int vr41xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) { - unsigned long alarm_sec; + time64_t alarm_sec; struct rtc_time *time = &wkalrm->time; - alarm_sec = mktime(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, - time->tm_hour, time->tm_min, time->tm_sec); + alarm_sec = mktime64(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, + time->tm_hour, time->tm_min, time->tm_sec); spin_lock_irq(&rtc_lock); From patchwork Fri Apr 20 16:14:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 902026 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40SLYy0jKcz9ry1 for ; Sat, 21 Apr 2018 02:15:50 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752671AbeDTQPg (ORCPT ); Fri, 20 Apr 2018 12:15:36 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:52585 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751836AbeDTQO6 (ORCPT ); Fri, 20 Apr 2018 12:14:58 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue003 [212.227.15.129]) with ESMTPA (Nemesis) id 0MEJGG-1fBmf33Mb2-00FVyc; Fri, 20 Apr 2018 18:14:41 +0200 From: Arnd Bergmann To: Alessandro Zummo , Alexandre Belloni Cc: y2038@lists.linaro.org, Arnd Bergmann , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] rtc: ls1x: remove mktime usage Date: Fri, 20 Apr 2018 18:14:25 +0200 Message-Id: <20180420161433.3721192-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180420161433.3721192-1-arnd@arndb.de> References: <20180420161433.3721192-1-arnd@arndb.de> X-Provags-ID: V03:K1:jLE80nIlTuHNBXQS5Q/kQoDTiwWNUWQEnwnlls4orHmeBQUKjjB N77cwiVuy6dsEhFiEXrwHIi9VkkjydOE/7GwGMuK5h7N27usXUdEy0mqvlyNW2cdBGbuhxO VczAqeW+ALJK3NgfG3vT/lV/akWejvHBZmQmu3QjroztusFbju0KENnqVEKqFKHBAeRBYkZ 05/1TJCNDmQjATPXoEREA== X-UI-Out-Filterresults: notjunk:1; V01:K0:4BCmzUPsy58=:umGPZc5w0R0G9gUX/EFSYp 5h/BwkQdvU83AX1DnPvFpsVD+t4tUuV2Y7eabH9Z5bchs/vfHkUI0gwcDofv5gKBmThHHAlCu W1wgGlfecIAz5/DR8oh5KLo9bfM4hQT4ZK4n29pY9PEIGXagZcpmhUEv6i3Ezzxl6rNFMcXfV fBnVtJhE5Y+PFNGwO+ckQPFO199/bde840s6qDVwPz7ncHlOUGJz8hiEIFjFJj4FXWbQk+l3q wR7wNvlt9Ph9EF3osXjD1OfOUHuTPM8DG3pNarzjdLRPzj5jrmmBaCHz3tBPJsOjns3bpb69s Zeh3gGWTH5sfXsz6o0x6JVXOoGd2dGy99HHx3itiTClxAHIrScdkqQdiBqfIjEU4bET1DeHqp oXgMME0xyr3cJiWV1E2nLvN7NjEXdalE1bUkvb7wyXwV/qI2Q2aTDP3hoVmVWgdpHfepvZnru hT0hs5PNx6rSnCNURlryRi8AEFwa+/AFbSZ77WvGwE4AbdDHF0jDT30AsAqSMWWB3QkiiPKeF KwumMcnOcJhfSauan7GIsnRz4LDBZYNZEHRCKYlYxHeWnYuR2OVdPU3DlRcVRf8tnVfau/lcb +7iHg8kxkWU9Mg/J2+YmswZloppSF9DK9wRMIXHUUoh0TIzqLmDz3mfIL7p66z/qlTvw1/bVO PJPkyRopIAvbcH0Qps7jkZjmUfJGJm0D8FCbaaKe72CzqjunvjEV3hSrWlw6Xz+jtJjjq2vjS 8jv1VoHmLfxQn/dTp4swoPYt9NiQG8PC9pBR+w== Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org The loongson1 platform is 32-bit, so storing a time value in 32 bits suffers from limited range. In this case it is likely to be correct until 2106, but it's better to avoid the limitation and just use the time64_t based mktime64() and rtc_time64_to_tm() interfaces. The hardware uses a 32-bit year number, and time64_t can cover that entire range. Signed-off-by: Arnd Bergmann --- drivers/rtc/rtc-ls1x.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/rtc/rtc-ls1x.c b/drivers/rtc/rtc-ls1x.c index 045af1135e48..de86f9fabc11 100644 --- a/drivers/rtc/rtc-ls1x.c +++ b/drivers/rtc/rtc-ls1x.c @@ -87,16 +87,17 @@ static int ls1x_rtc_read_time(struct device *dev, struct rtc_time *rtm) { - unsigned long v, t; + unsigned long v; + time64_t t; v = readl(SYS_TOYREAD0); t = readl(SYS_TOYREAD1); memset(rtm, 0, sizeof(struct rtc_time)); - t = mktime((t & LS1X_YEAR_MASK), ls1x_get_month(v), + t = mktime64((t & LS1X_YEAR_MASK), ls1x_get_month(v), ls1x_get_day(v), ls1x_get_hour(v), ls1x_get_min(v), ls1x_get_sec(v)); - rtc_time_to_tm(t, rtm); + rtc_time64_to_tm(t, rtm); return 0; } From patchwork Fri Apr 20 16:14:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 902025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-rtc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40SLYN4qp1z9ry1 for ; Sat, 21 Apr 2018 02:15:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752414AbeDTQPG (ORCPT ); Fri, 20 Apr 2018 12:15:06 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:36201 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751092AbeDTQPD (ORCPT ); Fri, 20 Apr 2018 12:15:03 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue003 [212.227.15.129]) with ESMTPA (Nemesis) id 0LhzeA-1eeMmj0RU2-00nC2K; Fri, 20 Apr 2018 18:14:47 +0200 From: Arnd Bergmann To: Alessandro Zummo , Alexandre Belloni Cc: y2038@lists.linaro.org, Arnd Bergmann , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] rtc: tps6586x: remove mktime usage Date: Fri, 20 Apr 2018 18:14:26 +0200 Message-Id: <20180420161433.3721192-3-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180420161433.3721192-1-arnd@arndb.de> References: <20180420161433.3721192-1-arnd@arndb.de> X-Provags-ID: V03:K1:uFk+XX53/Bun0nehYpCnUvhWFTU85ztqI+ZUVYREyY7ClPW/b/m dYt+MXwYQY2GDInUkNGWZE5D3jKkkfnMg3q2JdF1GpEvqU/NyZ7W7W8s8/0PC5bmoxU+9Nr o0fP/J2pJiQpiSNeM4sCZanRYykTof5qHxjIQv27wp+quVhXDeNWfNfKxhL7Qtsb8eS3/PY G3CEZUkV3EqQVQ2kd+EIg== X-UI-Out-Filterresults: notjunk:1; V01:K0:f7sSTuXSSpE=:PscYx+5khXoWBuyf9Kwhn0 NeIp+C3b+2Es1jINxyzosxTkiD10E6MXnSGg4M+us+apa4fg4PSXA73QlQhVe80EXdkT3Kjv9 i41npYRTsRQbjCipg5VcTBqNlz8drtOUqKAe4zq/21Qd+l/wO4qyE/YdBu3TYJUCjVnOGPIGB Dil1zMfYqZhmajD8Atg08VE7DrBLWaCmTHutZdO3ZWUpT25q3DIspwLcJF5yfZj5XNvQpbb6p f+Ojq9e0Za4gmbWzf+DZFgrXr5XjmjjV0gOi9WlsJn1yEqgnLKceOvJDIwjVTG7Kn+22TN6HV WyeSomVeOhyPxLzKvki03Iu6d5kBjXlVYhW9SR86Oh6CC2Aew60jMTg0B8X4yFFfUek+S1/Qu gS8cSEd/0Snoul2EDbN9JdMTXCKDT6pzs4QLlOfeypm4EPmfJ4zFv6mRdzvvkn6CAC9xaGD8n 33O4Wgo3LFMB0j1Mpi1CH2LTigjzzpgky/uWJAF3FZmWk0mTGg4F91YepTVyBeagwIeX9FN6k /0mumc+0kWI4VW1VuKLGI6ijuhDy2WI9TiogYbb+tX6JaWdZwljT0ZliSGOvq2d9cW/ofSHX1 9dB8cKuOJyThqL3XXLhy/o7iIcxhNprRpBNjvwu/OoCLAPkBg7kfIsxVl2xNp4vhYlYHz8AFp N4tEXCwh/V22gr/BALpOptjkKAgJo7YuKHcPNa8VOMkvPssqoZSrxPr6geikRktufm9GwmGEb zQ8cn9yb+SJshUAg+NowlUWdc0ow0h6IRe+azw== Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org The tps6586x use a 64-bit 'epoch_start' value, but then computes that value using an 'mktime()', which has a smaller range and overflows in 2106 at the latest. As both the hardware and the subsystem interface support wider than 32-bit ranges for rtc times here, let's change all the operations on 'seconds' to time64_t. Signed-off-by: Arnd Bergmann --- drivers/rtc/rtc-tps6586x.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/rtc/rtc-tps6586x.c b/drivers/rtc/rtc-tps6586x.c index d7785ae0a2b4..46a19adf9a96 100644 --- a/drivers/rtc/rtc-tps6586x.c +++ b/drivers/rtc/rtc-tps6586x.c @@ -58,7 +58,7 @@ struct tps6586x_rtc { struct rtc_device *rtc; int irq; bool irq_en; - unsigned long long epoch_start; + time64_t epoch_start; }; static inline struct device *to_tps6586x_dev(struct device *dev) @@ -71,7 +71,7 @@ static int tps6586x_rtc_read_time(struct device *dev, struct rtc_time *tm) struct tps6586x_rtc *rtc = dev_get_drvdata(dev); struct device *tps_dev = to_tps6586x_dev(dev); unsigned long long ticks = 0; - unsigned long seconds; + time64_t seconds; u8 buff[6]; int ret; int i; @@ -98,11 +98,11 @@ static int tps6586x_rtc_set_time(struct device *dev, struct rtc_time *tm) struct tps6586x_rtc *rtc = dev_get_drvdata(dev); struct device *tps_dev = to_tps6586x_dev(dev); unsigned long long ticks; - unsigned long seconds; + time64_t seconds; u8 buff[5]; int ret; - rtc_tm_to_time(tm, &seconds); + seconds = rtc_tm_to_time64(tm); if (seconds < rtc->epoch_start) { dev_err(dev, "requested time unsupported\n"); return -EINVAL; @@ -157,7 +157,7 @@ static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) { struct tps6586x_rtc *rtc = dev_get_drvdata(dev); struct device *tps_dev = to_tps6586x_dev(dev); - unsigned long seconds; + time64_t seconds; unsigned long ticks; unsigned long rtc_current_time; unsigned long long rticks = 0; @@ -166,7 +166,7 @@ static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) int ret; int i; - rtc_tm_to_time(&alrm->time, &seconds); + seconds = rtc_tm_to_time64(&alrm->time); if (alrm->enabled && (seconds < rtc->epoch_start)) { dev_err(dev, "can't set alarm to requested time\n"); @@ -213,7 +213,7 @@ static int tps6586x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) struct tps6586x_rtc *rtc = dev_get_drvdata(dev); struct device *tps_dev = to_tps6586x_dev(dev); unsigned long ticks; - unsigned long seconds; + time64_t seconds; u8 buff[3]; int ret; @@ -227,7 +227,7 @@ static int tps6586x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) seconds = ticks >> 10; seconds += rtc->epoch_start; - rtc_time_to_tm(seconds, &alrm->time); + rtc_time64_to_tm(seconds, &alrm->time); return 0; } @@ -261,7 +261,7 @@ static int tps6586x_rtc_probe(struct platform_device *pdev) rtc->irq = platform_get_irq(pdev, 0); /* Set epoch start as 00:00:00:01:01:2009 */ - rtc->epoch_start = mktime(2009, 1, 1, 0, 0, 0); + rtc->epoch_start = mktime64(2009, 1, 1, 0, 0, 0); /* 1 kHz tick mode, enable tick counting */ ret = tps6586x_update(tps_dev, RTC_CTRL,