From patchwork Mon Jun 19 09:36:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 105811 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp786833qgd; Mon, 19 Jun 2017 02:37:16 -0700 (PDT) X-Received: by 10.98.202.210 with SMTP id y79mr24745834pfk.230.1497865036607; Mon, 19 Jun 2017 02:37:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497865036; cv=none; d=google.com; s=arc-20160816; b=RDkQndjkSlCeE+aPqURR8bdwmqEhWPaZ+qQhg3DWMccxUU/RMb44Y+ahvAfj1t659k 8Hkc3H3WzkanGzVF5TrE5wVgW7zdWRTjH1NXN4D7EGjl/XDvK0W/ZuXLHvJZl6DH2zb8 GsVH6NAOGhnylXp0w03Iqon3zObmhx/tVAxl/b3txGU0XjUk5opQJ8waXKEbh4iUSZwM dqaps2xJYGTx+B/phZL4nk9TIksHTD0ppp4h3mPwdOhe0+krca+sYELDm2t0+NT+lXIP /Xcc6w6Z3JNNc3oyv4gg/xmZClLWI2BrmKvswvt1sGbSYXbkq4YWsy242XLflap/4kUJ r6WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=aDscxiEh3kfhaecNLT7CVn6qG5e+DMfx9s5gdFXuXFE=; b=NviX6d1RH+uG48cCNH8pu9tgqCAxsCZqae4f00AtTyaQ3qp0cK5NTxmV5f9iUs5vnF 0xw6+qmYgeV77evtSE40PHbULXPatIQzIfJ75M5fGOSfzirpVRcflhD3kaTnkleFZat0 0se52+CS+gd1wASRd+cHQ3e1r72aarjLeGF1uLnwRJb/rCQfYC51qSUfXjTjih3c4TLh 40cVB3QtzvuVRV0Epbpoa+cn8CC+G+hhrMAi+J9sQLTR4mpASSK7lvEKLLsnorxNyipX tNnB9d0jZjK/c3DaCRztfY9JrIAVi7PzXGEYjq66DHa3G2LzBFG74bp8kJI969E7uHBf F5Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=P42io1RG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b24si6937568pfh.9.2017.06.19.02.37.16; Mon, 19 Jun 2017 02:37:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=P42io1RG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753925AbdFSJhA (ORCPT + 25 others); Mon, 19 Jun 2017 05:37:00 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:36178 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753783AbdFSJg5 (ORCPT ); Mon, 19 Jun 2017 05:36:57 -0400 Received: by mail-wm0-f46.google.com with SMTP id m125so74062695wmm.1 for ; Mon, 19 Jun 2017 02:36:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aDscxiEh3kfhaecNLT7CVn6qG5e+DMfx9s5gdFXuXFE=; b=P42io1RG9fFUovQuzSDCfhexhfJF0ia+iqUvtOtga4u1TowUTXhUGiTicOIGOP2E6p VZbK02VXjEJtsCUntpvf6KpPXpLme1XJIQNYQvU+tWPsfXCFLkVy9COdarsGNIgK/pCg VxdNIRbO+eySDTPK/iqLNntI9IfEZBVRSUgFw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aDscxiEh3kfhaecNLT7CVn6qG5e+DMfx9s5gdFXuXFE=; b=Ae1B60dQNM83uBgBBhinff9T5iwDIQD0C422hpgMJmrPoC1Jj4G/JZSBkVIVvGPhbW pr+sYXP/kqkoeWZQCi/K3WVmcGlU1Gt1daYB5rXt9EkPhsR7/ite70btUGIHBIKtOFB0 EQbacapZ26Bp9qtvMU+yPnIeRQfJUF9wkJJp7jTrVcXbZrJHRehnYw11lykouxSKO97n RczBaee+GV/QSVvSwZ4W9F6owtOVb9mOti+2B0AmxR0/XvvrySBQYGCqIzvSrU0WdkKg 2ImwxEWMNtCuiteJxExJLUVC13HPA7KITgA52l4m++k9/DElCfzM5AWd69fijogAczL3 izaA== X-Gm-Message-State: AKS2vOxi77C3IPdElijL5YehhLnCGs1AxT1gKQGmngD9NSpk1L7GqJlb g9mJtPO71gnIKG3y X-Received: by 10.28.11.145 with SMTP id 139mr12167224wml.11.1497865016090; Mon, 19 Jun 2017 02:36:56 -0700 (PDT) Received: from lmenx321.st.com. ([80.215.35.135]) by smtp.gmail.com with ESMTPSA id y2sm11037024wme.12.2017.06.19.02.36.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Jun 2017 02:36:55 -0700 (PDT) From: Benjamin Gaignard To: john.stultz@linaro.org, tglx@linutronix.de, sboyd@codeaurora.org, shuah@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, patrice.chotard@st.com, a.zummo@towertech.it, alexandre.belloni@free-electrons.com, linux-arm-kernel@lists.infradead.org, rtc-linux@googlegroups.com Cc: linaro-kernel@lists.linaro.org, Benjamin Gaignard Subject: [PATCH v2 1/3] tools: timer: add rtctest_setdate Date: Mon, 19 Jun 2017 11:36:20 +0200 Message-Id: <1497864982-29284-2-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org> References: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This tool allow to set directly the time and date to a RTC device. Unlike other tools isn't doens't use "struct timeval" or "time_t" so it is safe for 32bits platforms when testing for y2038/2106 bug. Signed-off-by: Benjamin Gaignard --- tools/testing/selftests/timers/Makefile | 2 +- tools/testing/selftests/timers/rtctest_setdate.c | 86 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/timers/rtctest_setdate.c -- 1.9.1 diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile index 5fa1d7e9..54481f1 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile @@ -9,7 +9,7 @@ TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \ TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \ skew_consistency clocksource-switch leap-a-day \ - leapcrash set-tai set-2038 set-tz + leapcrash set-tai set-2038 set-tz rtctest_setdate include ../lib.mk diff --git a/tools/testing/selftests/timers/rtctest_setdate.c b/tools/testing/selftests/timers/rtctest_setdate.c new file mode 100644 index 0000000..2cb7848 --- /dev/null +++ b/tools/testing/selftests/timers/rtctest_setdate.c @@ -0,0 +1,86 @@ +/* Real Time Clock Driver Test + * by: Benjamin Gaignard (benjamin.gaignard@linaro.org) + * + * To build + * gcc rtctest_setdate.c -o rtctest_setdate + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const char default_time[] = "00:00:00"; + +int main(int argc, char **argv) +{ + int fd, retval; + struct rtc_time new, current; + const char *rtc, *date; + const char *time = default_time; + + switch (argc) { + case 4: + time = argv[3]; + /* FALLTHROUGH */ + case 3: + date = argv[2]; + rtc = argv[1]; + break; + default: + fprintf(stderr, "usage: rtctest_setdate [HH:MM:SS]\n"); + return 1; + } + + fd = open(rtc, O_RDONLY); + if (fd == -1) { + perror(rtc); + exit(errno); + } + + sscanf(date, "%d-%d-%d", &new.tm_mday, &new.tm_mon, &new.tm_year); + new.tm_mon -= 1; + new.tm_year -= 1900; + sscanf(time, "%d:%d:%d", &new.tm_hour, &new.tm_min, &new.tm_sec); + + fprintf(stderr, "Test will set RTC date/time to %d-%d-%d, %02d:%02d:%02d.\n", + new.tm_mday, new.tm_mon + 1, new.tm_year + 1900, + new.tm_hour, new.tm_min, new.tm_sec); + + /* Write the new date in RTC */ + retval = ioctl(fd, RTC_SET_TIME, &new); + if (retval == -1) { + perror("RTC_SET_TIME ioctl"); + close(fd); + exit(errno); + } + + /* Read back */ + retval = ioctl(fd, RTC_RD_TIME, ¤t); + if (retval == -1) { + perror("RTC_RD_TIME ioctl"); + exit(errno); + } + + fprintf(stderr, "\n\nCurrent RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n", + current.tm_mday, current.tm_mon + 1, current.tm_year + 1900, + current.tm_hour, current.tm_min, current.tm_sec); + + close(fd); + return 0; +} From patchwork Mon Jun 19 09:36:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 105812 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp786835qgd; Mon, 19 Jun 2017 02:37:17 -0700 (PDT) X-Received: by 10.99.125.2 with SMTP id y2mr25212742pgc.10.1497865037331; Mon, 19 Jun 2017 02:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497865037; cv=none; d=google.com; s=arc-20160816; b=eJ3fe/+YiWwgN5qgxvZwv2s3ndwAiqm/x7AixlvMMGb8AJ+Qc+9YTEONTtIwMDnQsK POu6uMrW4Z0n7wagkGZ3oLYQ99de6aprQyPWsXyuXLO8MjAVCM5disiPkSfVOndvi00z yqv4H32vdaCGHjmQjDiDYX/voAZi7T2sv3epV/AmkKv0LCad+4pRHguSebDnxSZqaHpw alNEW0q9HTA6wdrIJYCiSVkqZcYGSrcGLwkgVaYnzYKjS3fEnLfXU1g6EPRDiTfbbm0R 5s/E9700iGkMG9/ARwyjxkSHpY51CF8fGZ4Gn4iByKpuxd6W5+qXbiWv6vBd2aurlciU zPoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=FbCt3l0hrNin0GsxE7vtSdlS4zINZAxU5/0qZ0h9j6w=; b=Pq3odG4R1DrT/6As2vNoD/bVm7LYEQ/k54M+IyQ6Mj86FTVPE7H36vYIRXrM0+Ujgd pf4H4LMQ4EBy4vll7LKVWqw1oCRDnYhE+Hz3Rzgcgvv3qN0mbhY8/rFIBJM+/3mbnEpc e64vQtylCb6AcqFsGzyerE4eMhlHSf0qllyM7HbIjzC2jgN8xkh1LHkygpARuTJwYs/p 3zGBubSf5ttNbcgA+PcREN4fhp3PUBHPVi7pVVbyqqlT+GXaQSFfuDIczSAm3RmzeH80 V6jm+l9xJS1IPl5JctuYlCiVbN3b78pG3UBymfjuxMZ2Vy06jiyi1JSKuJXOMjrdb2Se WZ7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=Z/Op1DjD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b24si6937568pfh.9.2017.06.19.02.37.17; Mon, 19 Jun 2017 02:37:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=Z/Op1DjD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753926AbdFSJhG (ORCPT + 25 others); Mon, 19 Jun 2017 05:37:06 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:35619 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753902AbdFSJg7 (ORCPT ); Mon, 19 Jun 2017 05:36:59 -0400 Received: by mail-wm0-f44.google.com with SMTP id x70so73699637wme.0 for ; Mon, 19 Jun 2017 02:36:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FbCt3l0hrNin0GsxE7vtSdlS4zINZAxU5/0qZ0h9j6w=; b=Z/Op1DjD0Tgy1COCeoIvXSJsTfK0mkI6a9BKV4KDSmKRUehj6dQCFEeMCK1cLJT4n9 1gzeWAlS5XzwR2oh547176iz5UlE/h3tp0HbH+zHO86A5NqScJ2dWEmdgJT8xj5ABHlE TiRg4QP9ddujbGsG/egj2BU3r/8iaE36R9ODk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FbCt3l0hrNin0GsxE7vtSdlS4zINZAxU5/0qZ0h9j6w=; b=FeNx3ULFL1+tYlFVNEBpmnLotA5FoxIlhMGYAVQ6J3cnWU4x70bAjc5Pycubp0r5jW mXxfrnwm1Ea2lGbdJVX0tX5ucLcSzX1j4QmZq30s/O39mKog/d2kLSBVdOSDfIlo6TaW DPVLvnZqZRdsdV5UZV4g2JMscVcXTqjdeSyWkVLwzOY9esFpuXoLwAe51xMic6NMa3uq B5zdlD1PumZlNhL3ORf+p3XXbkZqnXOT2neAHn/Uru0etlIeWEn2Im6y/Q+HXi5e2UOy k4iIqoD/Fm4g4eoHQnL1xRJbyY/WvTRddp8FruDIuzr6+oorKmLtqsaf8/sxSQpXiUDl mNVA== X-Gm-Message-State: AKS2vOxHEHgDsgL7TY4ZdC9UANfXaMQEic8H+CTsgU72Gy0g3ruHCGzo X+Uy5Jamb09kn/6K X-Received: by 10.28.87.132 with SMTP id l126mr14963452wmb.95.1497865017687; Mon, 19 Jun 2017 02:36:57 -0700 (PDT) Received: from lmenx321.st.com. ([80.215.35.135]) by smtp.gmail.com with ESMTPSA id y2sm11037024wme.12.2017.06.19.02.36.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Jun 2017 02:36:57 -0700 (PDT) From: Benjamin Gaignard To: john.stultz@linaro.org, tglx@linutronix.de, sboyd@codeaurora.org, shuah@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, patrice.chotard@st.com, a.zummo@towertech.it, alexandre.belloni@free-electrons.com, linux-arm-kernel@lists.infradead.org, rtc-linux@googlegroups.com Cc: linaro-kernel@lists.linaro.org, Benjamin Gaignard Subject: [PATCH v2 2/3] tool: timer: rtctest add check for problematic dates Date: Mon, 19 Jun 2017 11:36:21 +0200 Message-Id: <1497864982-29284-3-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org> References: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some dates could be problematic because they reach the limits of RTC hardware capabilities. This patch add various of them but since it will change RTC date it will be activated only when 'd' args is set. Signed-off-by: Benjamin Gaignard --- tools/testing/selftests/timers/rtctest.c | 121 ++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 4 deletions(-) -- 1.9.1 diff --git a/tools/testing/selftests/timers/rtctest.c b/tools/testing/selftests/timers/rtctest.c index 4230d30..715a016 100644 --- a/tools/testing/selftests/timers/rtctest.c +++ b/tools/testing/selftests/timers/rtctest.c @@ -21,6 +21,9 @@ #include #include +#ifndef ARRAY_SIZE +# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif /* * This expects the new RTC class driver framework, working with @@ -29,23 +32,77 @@ */ static const char default_rtc[] = "/dev/rtc0"; +static struct rtc_time cutoff_dates[] = { + { + .tm_year = 70, /* 1970 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 137, /* 2037 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 138, /* 2038 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 199, /* 2099 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 200, /* 2100 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 205, /* 2105 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 206, /* 2106 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 361, /* 2261 -1900 */ + .tm_mday = 1, + }, + { + .tm_year = 362, /* 2262 -1900 */ + .tm_mday = 1, + }, +}; + +static int compare_dates(struct rtc_time *a, struct rtc_time *b) +{ + if (a->tm_year != b->tm_year || + a->tm_mon != b->tm_mon || + a->tm_mday != b->tm_mday || + a->tm_hour != b->tm_hour || + a->tm_min != b->tm_min || + ((b->tm_sec - a->tm_sec) > 1)) + return 1; + + return 0; +} int main(int argc, char **argv) { - int i, fd, retval, irqcount = 0; + int i, fd, retval, irqcount = 0, dangerous = 0; unsigned long tmp, data; struct rtc_time rtc_tm; const char *rtc = default_rtc; struct timeval start, end, diff; switch (argc) { + case 3: + if (*argv[2] == 'd') + dangerous = 1; case 2: rtc = argv[1]; /* FALLTHROUGH */ case 1: break; default: - fprintf(stderr, "usage: rtctest [rtcdev]\n"); + fprintf(stderr, "usage: rtctest [rtcdev] [d]\n"); return 1; } @@ -202,7 +259,7 @@ int main(int argc, char **argv) /* not all RTCs support periodic IRQs */ if (errno == EINVAL) { fprintf(stderr, "\nNo periodic IRQ support\n"); - goto done; + goto test_DATE; } perror("RTC_IRQP_READ ioctl"); exit(errno); @@ -221,7 +278,7 @@ int main(int argc, char **argv) if (errno == EINVAL) { fprintf(stderr, "\n...Periodic IRQ rate is fixed\n"); - goto done; + goto test_DATE; } perror("RTC_IRQP_SET ioctl"); exit(errno); @@ -269,6 +326,62 @@ int main(int argc, char **argv) } } +test_DATE: + if (!dangerous) + goto done; + + fprintf(stderr, "\nTesting problematic dates\n"); + + for (i = 0; i < ARRAY_SIZE(cutoff_dates); i++) { + struct rtc_time current; + + /* Write the new date in RTC */ + retval = ioctl(fd, RTC_SET_TIME, &cutoff_dates[i]); + if (retval == -1) { + perror("RTC_SET_TIME ioctl"); + close(fd); + exit(errno); + } + + /* Read back */ + retval = ioctl(fd, RTC_RD_TIME, ¤t); + if (retval == -1) { + perror("RTC_RD_TIME ioctl"); + exit(errno); + } + + if(compare_dates(&cutoff_dates[i], ¤t)) { + fprintf(stderr,"Setting date %d failed\n", + cutoff_dates[i].tm_year + 1900); + goto done; + } + + cutoff_dates[i].tm_sec += 5; + + /* Write the new alarm in RTC */ + retval = ioctl(fd, RTC_ALM_SET, &cutoff_dates[i]); + if (retval == -1) { + perror("RTC_ALM_SET ioctl"); + close(fd); + exit(errno); + } + + /* Read back */ + retval = ioctl(fd, RTC_ALM_READ, ¤t); + if (retval == -1) { + perror("RTC_ALM_READ ioctl"); + exit(errno); + } + + if(compare_dates(&cutoff_dates[i], ¤t)) { + fprintf(stderr,"Setting alarm %d failed\n", + cutoff_dates[i].tm_year + 1900); + goto done; + } + + fprintf(stderr, "Setting year %d is OK \n", + cutoff_dates[i].tm_year + 1900); + } done: fprintf(stderr, "\n\n\t\t\t *** Test complete ***\n"); From patchwork Mon Jun 19 09:36:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 105813 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp786841qgd; Mon, 19 Jun 2017 02:37:18 -0700 (PDT) X-Received: by 10.98.198.201 with SMTP id x70mr21566691pfk.232.1497865037982; Mon, 19 Jun 2017 02:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497865037; cv=none; d=google.com; s=arc-20160816; b=II0GbeDvcprrJMNx7eXLliCsKXgTjPNGGn5Ubu2MbhkFMPjo2saVgi9eySYeHQEu6Y wFTGqV4zq728WSEhQZjZIEI+sr5blQfAq2UjWUDPPc4UWKIC1B86oMRuXa6NR5G7jhKs euGtnRszdNWFDM9k/G1lxL9PZQ8Ybm+Cehj7MdAENRQtJqgBYtUEIPkY3BziluNZ27X9 AUJRLhIWr+2NrdN6xWamb6LqsJgtOHYhKuEutiOye6PqDUjH5V009Hrx0g14VIEqnw+N BtySYS9t8sgIDwz7oFLdswJMCyn1Ucokns/ufM4A3MD893QDmnlgTcCVClkHYoiVm6di PYRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=F/N9eNsJZr2+7DPpKTbXLtBvEtQ7sHqQMh9idFnIQbQ=; b=KS9VWAdlrScgozUuKDnW6TTr1hHMUJsW1piEFI9MICAPjeixRbyPINJkKSWXUFhMA3 gLvew2BQX2mVqpCxH5hPqaSMW5iHORmll/ywriV8H9YRwg6MxIFQ1cJ4+HpHTTgl/cId FBaPm+9ii6kQ6jesR1L9H2XagjeYcXBGOHpdvNznE8yLNDoHdTTZfEPk7MeTbB+q1osx YERUNUryaHBpNeHMnLmYxbOjSgJx8HE/XEXh4Tc2aAyshRw/wbNO7OzwZnnigwUKQyfK A8yvBDPScmS/lgGPMSWjcRXQldBFUBALcfyc9aep8Kkva53lgy9KXj6BLLyvkgohLjp0 cSQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=Ngm4UyNc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b24si6937568pfh.9.2017.06.19.02.37.17; Mon, 19 Jun 2017 02:37:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=Ngm4UyNc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753952AbdFSJhM (ORCPT + 25 others); Mon, 19 Jun 2017 05:37:12 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:37220 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753735AbdFSJhK (ORCPT ); Mon, 19 Jun 2017 05:37:10 -0400 Received: by mail-wm0-f47.google.com with SMTP id d73so68221958wma.0 for ; Mon, 19 Jun 2017 02:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=F/N9eNsJZr2+7DPpKTbXLtBvEtQ7sHqQMh9idFnIQbQ=; b=Ngm4UyNcUo3CerdtKtpWTMmFHkCrcc03iQitey690RPW7OyKZazYrnzYl7muCA4wSo gbeOGKVZ7r4knPjJhUxSX5McYF36EUaLklaXV7KdU2xnCEeHAzbonvMq497XA8imr0g0 3aFlHU3BOrsBRtqXlRyj7q5JmxaJxMptnx6p8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F/N9eNsJZr2+7DPpKTbXLtBvEtQ7sHqQMh9idFnIQbQ=; b=JPyKW7RSvzjAmlUT1mqGK8fe58y7/fsC5per94L28EaACriaozr8E+4uSluphV+rht UNQdGmJsMwJUvKdTtu49AZF52oldvZhvEjRDEPJgvmtwXxynVmpmPcbBrgUtFSwL5sO0 zwtDXsHIyW8kz7vHRVxc07uvlLAnJ/btEMeMyFFmEXzfvUFMQmuBPE7TkLxjQhYseiRE 4FAVAzAGfypOFWQkGhuLJIbjnI6/MU6a5ETtwSJyOom2eZT0uVGZacqJqLvWcnmH1LKW AOSDV/+20mA9VzsyXbNjkB4pOiABToOqvyeRmVIgeLd+sHnKVaLNY2nwNHz+0o2v/ICF AU/A== X-Gm-Message-State: AKS2vOw2nyiZaYhsX1/O2pyIzxb6IDI0j3oAde/W37glwbmB2p8jKGA/ numB676+nNvX2D0o X-Received: by 10.28.126.67 with SMTP id z64mr4340008wmc.65.1497865019445; Mon, 19 Jun 2017 02:36:59 -0700 (PDT) Received: from lmenx321.st.com. ([80.215.35.135]) by smtp.gmail.com with ESMTPSA id y2sm11037024wme.12.2017.06.19.02.36.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Jun 2017 02:36:59 -0700 (PDT) From: Benjamin Gaignard To: john.stultz@linaro.org, tglx@linutronix.de, sboyd@codeaurora.org, shuah@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, patrice.chotard@st.com, a.zummo@towertech.it, alexandre.belloni@free-electrons.com, linux-arm-kernel@lists.infradead.org, rtc-linux@googlegroups.com Cc: linaro-kernel@lists.linaro.org, Benjamin Gaignard Subject: [PATCH v2 3/3] rtc: st-lpc: make it robust against y2038/2106 bug Date: Mon, 19 Jun 2017 11:36:22 +0200 Message-Id: <1497864982-29284-4-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org> References: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make driver use u64 variables and functions to be sure that it will support dates after year 2038. Signed-off-by: Benjamin Gaignard Acked-by: Patrice Chotard --- drivers/rtc/rtc-st-lpc.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) -- 1.9.1 diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c index 74c0a33..82b0af1 100644 --- a/drivers/rtc/rtc-st-lpc.c +++ b/drivers/rtc/rtc-st-lpc.c @@ -99,7 +99,7 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm) lpt = ((unsigned long long)lpt_msb << 32) | lpt_lsb; do_div(lpt, rtc->clkrate); - rtc_time_to_tm(lpt, tm); + rtc_time64_to_tm(lpt, tm); return 0; } @@ -107,13 +107,10 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm) static int st_rtc_set_time(struct device *dev, struct rtc_time *tm) { struct st_rtc *rtc = dev_get_drvdata(dev); - unsigned long long lpt; - unsigned long secs, flags; - int ret; + unsigned long long lpt, secs; + unsigned long flags; - ret = rtc_tm_to_time(tm, &secs); - if (ret) - return ret; + secs = rtc_tm_to_time64(tm); lpt = (unsigned long long)secs * rtc->clkrate; @@ -161,13 +158,13 @@ static int st_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *t) { struct st_rtc *rtc = dev_get_drvdata(dev); struct rtc_time now; - unsigned long now_secs; - unsigned long alarm_secs; + unsigned long long now_secs; + unsigned long long alarm_secs; unsigned long long lpa; st_rtc_read_time(dev, &now); - rtc_tm_to_time(&now, &now_secs); - rtc_tm_to_time(&t->time, &alarm_secs); + now_secs = rtc_tm_to_time64(&now); + alarm_secs = rtc_tm_to_time64(&t->time); /* Invalid alarm time */ if (now_secs > alarm_secs)