From patchwork Mon Mar 19 23:48:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 887946 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=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 404t8V3BSZz9sWF for ; Tue, 20 Mar 2018 10:49:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965391AbeCSXsg (ORCPT ); Mon, 19 Mar 2018 19:48:36 -0400 Received: from mail.bootlin.com ([62.4.15.54]:54262 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964813AbeCSXsd (ORCPT ); Mon, 19 Mar 2018 19:48:33 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 2C8B1207E5; Tue, 20 Mar 2018 00:48:31 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.bootlin.com (Postfix) with ESMTPSA id CE0572069C; Tue, 20 Mar 2018 00:48:20 +0100 (CET) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 1/6] rtc: hctosys: Ensure system time doesn't overflow time_t Date: Tue, 20 Mar 2018 00:48:12 +0100 Message-Id: <20180319234817.16199-1-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.16.2 Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org On 32bit platforms, time_t is still a signed 32bit long. If it is overflowed, userspace and the kernel cant agree on the current system time. This causes multiple issues, in particular with systemd: https://github.com/systemd/systemd/issues/1143 A good workaround is to simply avoid using systohc which is something I greatly encourage as the time is better set by userspace. However, many distribution enable it and use systemd which is rendering the system unusable in case the RTC holds a date after 2038 (and more so after 2106). Many drivers have workaround for this case and they should be eliminated so there is only one place left to fix when userspace is able to cope with dates after the 31bit overflow. Signed-off-by: Alexandre Belloni --- drivers/rtc/hctosys.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c index e1cfa06810ef..e79f2a181ad2 100644 --- a/drivers/rtc/hctosys.c +++ b/drivers/rtc/hctosys.c @@ -49,6 +49,11 @@ static int __init rtc_hctosys(void) tv64.tv_sec = rtc_tm_to_time64(&tm); +#if BITS_PER_LONG == 32 + if (tv64.tv_sec > INT_MAX) + goto err_read; +#endif + err = do_settimeofday64(&tv64); dev_info(rtc->dev.parent, From patchwork Mon Mar 19 23:48:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 887941 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=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 404t780YzWz9sWB for ; Tue, 20 Mar 2018 10:48:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964877AbeCSXse (ORCPT ); Mon, 19 Mar 2018 19:48:34 -0400 Received: from mail.bootlin.com ([62.4.15.54]:54263 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964820AbeCSXsd (ORCPT ); Mon, 19 Mar 2018 19:48:33 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 66ED42072D; Tue, 20 Mar 2018 00:48:31 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.bootlin.com (Postfix) with ESMTPSA id 215C2206FB; Tue, 20 Mar 2018 00:48:21 +0100 (CET) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 2/6] rtc: mv: remove artificial limitation Date: Tue, 20 Mar 2018 00:48:13 +0100 Message-Id: <20180319234817.16199-2-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319234817.16199-1-alexandre.belloni@bootlin.com> References: <20180319234817.16199-1-alexandre.belloni@bootlin.com> Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org Dates after 2038 actually fit on 32 bits. The counter will overflow in 2106. Also, it is bad practice to reset the RTC to a default value. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-mv.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c index 944c5c0fadd0..bc52dbb0c0e2 100644 --- a/drivers/rtc/rtc-mv.c +++ b/drivers/rtc/rtc-mv.c @@ -223,7 +223,6 @@ static int __init mv_rtc_probe(struct platform_device *pdev) struct resource *res; struct rtc_plat_data *pdata; u32 rtc_time; - u32 rtc_date; int ret = 0; pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); @@ -259,17 +258,6 @@ static int __init mv_rtc_probe(struct platform_device *pdev) } } - /* - * A date after January 19th, 2038 does not fit on 32 bits and - * will confuse the kernel and userspace. Reset to a sane date - * (January 1st, 2013) if we're after 2038. - */ - rtc_date = readl(pdata->ioaddr + RTC_DATE_REG_OFFS); - if (bcd2bin((rtc_date >> RTC_YEAR_OFFS) & 0xff) >= 38) { - dev_info(&pdev->dev, "invalid RTC date, resetting to January 1st, 2013\n"); - writel(0x130101, pdata->ioaddr + RTC_DATE_REG_OFFS); - } - pdata->irq = platform_get_irq(pdev, 0); platform_set_drvdata(pdev, pdata); From patchwork Mon Mar 19 23:48:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 887945 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=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 404t8K2znLz9sWB for ; Tue, 20 Mar 2018 10:49:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965408AbeCSXsi (ORCPT ); Mon, 19 Mar 2018 19:48:38 -0400 Received: from mail.bootlin.com ([62.4.15.54]:54264 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964834AbeCSXsd (ORCPT ); Mon, 19 Mar 2018 19:48:33 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id B5D52206FB; Tue, 20 Mar 2018 00:48:31 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.bootlin.com (Postfix) with ESMTPSA id 6167020710; Tue, 20 Mar 2018 00:48:21 +0100 (CET) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 3/6] rtc: mrst: remove artificial limitation Date: Tue, 20 Mar 2018 00:48:14 +0100 Message-Id: <20180319234817.16199-3-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319234817.16199-1-alexandre.belloni@bootlin.com> References: <20180319234817.16199-1-alexandre.belloni@bootlin.com> Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org The hardware supports years up to 100 so don't limit the year to 2038 artificially. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-mrst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-mrst.c b/drivers/rtc/rtc-mrst.c index 901a8d170f68..fcb9de5218b2 100644 --- a/drivers/rtc/rtc-mrst.c +++ b/drivers/rtc/rtc-mrst.c @@ -122,7 +122,7 @@ static int mrst_set_time(struct device *dev, struct rtc_time *time) min = time->tm_min; sec = time->tm_sec; - if (yrs < 72 || yrs > 138) + if (yrs < 72 || yrs > 172) return -EINVAL; yrs -= 72; From patchwork Mon Mar 19 23:48:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 887944 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=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 404t8C0KQyz9sWB for ; Tue, 20 Mar 2018 10:49:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965535AbeCSXsj (ORCPT ); Mon, 19 Mar 2018 19:48:39 -0400 Received: from mail.bootlin.com ([62.4.15.54]:54265 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964848AbeCSXse (ORCPT ); Mon, 19 Mar 2018 19:48:34 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 014BA20710; Tue, 20 Mar 2018 00:48:31 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.bootlin.com (Postfix) with ESMTPSA id ABB2E20712; Tue, 20 Mar 2018 00:48:21 +0100 (CET) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 4/6] rtc: st-lpc: remove artificial limitation Date: Tue, 20 Mar 2018 00:48:15 +0100 Message-Id: <20180319234817.16199-4-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319234817.16199-1-alexandre.belloni@bootlin.com> References: <20180319234817.16199-1-alexandre.belloni@bootlin.com> Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org The LPC RTC supports dates way beyond 2038, don't limit it artificially as the kernel handles dates after 2038 properly. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-st-lpc.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c index 82b0af159a28..dcdd2b0a58f7 100644 --- a/drivers/rtc/rtc-st-lpc.c +++ b/drivers/rtc/rtc-st-lpc.c @@ -254,21 +254,6 @@ static int st_rtc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, rtc); - /* - * The RTC-LPC is able to manage date.year > 2038 - * but currently the kernel can not manage this date! - * If the RTC-LPC has a date.year > 2038 then - * it's set to the epoch "Jan 1st 2000" - */ - st_rtc_read_time(&pdev->dev, &tm_check); - - if (tm_check.tm_year >= (2038 - 1900)) { - memset(&tm_check, 0, sizeof(tm_check)); - tm_check.tm_year = 100; - tm_check.tm_mday = 1; - st_rtc_set_time(&pdev->dev, &tm_check); - } - rtc->rtc_dev = rtc_device_register("st-lpc-rtc", &pdev->dev, &st_rtc_ops, THIS_MODULE); if (IS_ERR(rtc->rtc_dev)) { From patchwork Mon Mar 19 23:48:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 887943 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=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 404t863WsGz9sWF for ; Tue, 20 Mar 2018 10:49:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965666AbeCSXsl (ORCPT ); Mon, 19 Mar 2018 19:48:41 -0400 Received: from mail.bootlin.com ([62.4.15.54]:54266 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964858AbeCSXse (ORCPT ); Mon, 19 Mar 2018 19:48:34 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 4D9B720712; Tue, 20 Mar 2018 00:48:32 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.bootlin.com (Postfix) with ESMTPSA id 007D92071E; Tue, 20 Mar 2018 00:48:21 +0100 (CET) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 5/6] rtc: 88pm80x: remove artificial limitation Date: Tue, 20 Mar 2018 00:48:16 +0100 Message-Id: <20180319234817.16199-5-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319234817.16199-1-alexandre.belloni@bootlin.com> References: <20180319234817.16199-1-alexandre.belloni@bootlin.com> Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org The 88pm80x supports time up to 2106 (it is a 32 bit counter). Also, the year will never be before 1970 as the RTC core forbids that. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-88pm80x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-88pm80x.c b/drivers/rtc/rtc-88pm80x.c index 466bf7f9a285..6cbafefa80a2 100644 --- a/drivers/rtc/rtc-88pm80x.c +++ b/drivers/rtc/rtc-88pm80x.c @@ -134,9 +134,9 @@ static int pm80x_rtc_set_time(struct device *dev, struct rtc_time *tm) struct pm80x_rtc_info *info = dev_get_drvdata(dev); unsigned char buf[4]; unsigned long ticks, base, data; - if ((tm->tm_year < 70) || (tm->tm_year > 138)) { + if (tm->tm_year > 206) { dev_dbg(info->dev, - "Set time %d out of range. Please set time between 1970 to 2038.\n", + "Set time %d out of range. Please set time between 1970 to 2106.\n", 1900 + tm->tm_year); return -EINVAL; } From patchwork Mon Mar 19 23:48:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 887942 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=bootlin.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 404t855LGmz9sWB for ; Tue, 20 Mar 2018 10:49:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964858AbeCSXtJ (ORCPT ); Mon, 19 Mar 2018 19:49:09 -0400 Received: from mail.bootlin.com ([62.4.15.54]:54268 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964834AbeCSXsn (ORCPT ); Mon, 19 Mar 2018 19:48:43 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 6A5AF20710; Tue, 20 Mar 2018 00:48:41 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (unknown [88.191.26.124]) by mail.bootlin.com (Postfix) with ESMTPSA id 4759620725; Tue, 20 Mar 2018 00:48:22 +0100 (CET) From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 6/6] rtc: 88pm860x: remove artificial limitation Date: Tue, 20 Mar 2018 00:48:17 +0100 Message-Id: <20180319234817.16199-6-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319234817.16199-1-alexandre.belloni@bootlin.com> References: <20180319234817.16199-1-alexandre.belloni@bootlin.com> Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org The 88pm860x supports time up to 2106 (it is a 32 bit counter). Also, the year will never be before 1970 as the RTC core forbids that. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-88pm860x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c index 19e53b3b8e00..01ffc0ef8033 100644 --- a/drivers/rtc/rtc-88pm860x.c +++ b/drivers/rtc/rtc-88pm860x.c @@ -135,9 +135,9 @@ static int pm860x_rtc_set_time(struct device *dev, struct rtc_time *tm) unsigned char buf[4]; unsigned long ticks, base, data; - if ((tm->tm_year < 70) || (tm->tm_year > 138)) { + if (tm->tm_year > 206) { dev_dbg(info->dev, "Set time %d out of range. " - "Please set time between 1970 to 2038.\n", + "Please set time between 1970 to 2106.\n", 1900 + tm->tm_year); return -EINVAL; }