From patchwork Fri Jun 16 14:03:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 105746 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp1321297qgd; Fri, 16 Jun 2017 07:05:22 -0700 (PDT) X-Received: by 10.84.178.4 with SMTP id y4mr13153258plb.158.1497621922030; Fri, 16 Jun 2017 07:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497621922; cv=none; d=google.com; s=arc-20160816; b=Eyh2oFci9/PK21FE/0SkzAIb4CmbsLmUYdWv+xugqj3Wz4/gIB+B47v9WTLCvvxzKi nvxNcEMIvwitiJ42QUeDtieTzQKH/jJYHI2JVoQ/WK2MZ4whP9F6dpWZDTnzR+2RgjTK ppBv4G7/ckjr1gsLQx9OIvyUwpnSHgllF5fW30nOeS1i0z8VCjI5LhrIbzkXxQj24rKt U+30JnH8XnBTg16e7HDTIeEtVs/rCNoA0JEa8S/gVpIyJp4sueLELvW87Q0n/RHLJ09N UZUyS21fk+qqjSqsaS/TT4QKnzCASL9l6c9ghaRDGmrrDlV+/tiAe3ReLcM5abqUOt9v BMXA== 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=EQ83oXWnJ3h0/EErc0CML5PVjPp/VmeMQvU8x3q+a3U=; b=YCYsI6IYdb41Gvb2jJMDRE7RKswt/8e39ziwhlxq/sSL3qmL030bBYZdrJmWjQtwtJ SJ9trNp4HJ+t70DWyap3beNurnbfibpW9ORRfp8IKhC9pbcdm97vBM80IQQdFDMllSqH EfDmmMScvJgtekGynx5ayqET6TgGqT5N1exZxpikjpcLBRG6WJUna7zv7y7zh439waWp eo1ijxJ9ga9aKVhAny5FW+2xiPUIDHyTp3P7WBKnl/qUPHWHMRo/dx20HZKsWHEHjZGk mqlJC42rS1e0WRH7bpwy9auDtR79LNa2Qdq3I0lNXCq33mZIZOJVb8L8Pnn8qLnCrw0T Qh8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=AnFHnPDt; 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 f192si2049730pgc.179.2017.06.16.07.05.21; Fri, 16 Jun 2017 07:05:22 -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=AnFHnPDt; 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 S1754036AbdFPOE4 (ORCPT + 25 others); Fri, 16 Jun 2017 10:04:56 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:33745 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754020AbdFPOEw (ORCPT ); Fri, 16 Jun 2017 10:04:52 -0400 Received: by mail-wm0-f51.google.com with SMTP id m7so4144061wmg.0 for ; Fri, 16 Jun 2017 07:04:51 -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=EQ83oXWnJ3h0/EErc0CML5PVjPp/VmeMQvU8x3q+a3U=; b=AnFHnPDthTQGfGbpo1wZ/9YdlwnGGp0ydELjdw7vYvNsAYHxM5+BpcqMJJDZxrmjUN m7MP6Bbq/N8KIh1shS5NJTuawCktixk83KVw6oWmksh46WdH0/gITZW6thdvX1SEUhpu Q9V6wiSZh/2Ggfmt9t2/8j/34hFbNlY53GKQc= 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=EQ83oXWnJ3h0/EErc0CML5PVjPp/VmeMQvU8x3q+a3U=; b=q9t+4zK5rRC4AN7yOIuUst6S+O4wEwUljXayieWNuBJsCEb15BC+YCZnZvxo4t2Rj7 B39ObYj8JReZx0mn0PCKvmc2aF+QIXEoeV8TLBhsv99v9yfi/sZXmhasw85PDMG8OfrX 4O0GJW96Xjg06uadicXS0MR8M/uXw5E2fouFhejvnLX4JfRNB23pRM73TydlBOZAcNuL pf0X/K8rIC9rF7wSLDDVa+CQT9tan9EpqV7aZsI850nGaZv9cltjnqw5GpA7iGuvTblN GgMVhQ+4XMYBGL52A/nMzPVFtAmvpfFA7kISp+HOyZdeIwW3GMi3LwQJj3gq21FGpCxL 1SeA== X-Gm-Message-State: AKS2vOyge43wEzTNPvg++PhmIatctb6WIe8wEtLhCuqXBGEzqkWUO03M PnHRYWXVJEFIZF0O X-Received: by 10.28.196.2 with SMTP id u2mr7621789wmf.104.1497621891011; Fri, 16 Jun 2017 07:04:51 -0700 (PDT) Received: from lmenx321.st.com. ([80.214.78.131]) by smtp.gmail.com with ESMTPSA id h12sm1883277wrc.43.2017.06.16.07.04.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Jun 2017 07:04:50 -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 1/3] tools: timer: add rtctest_setdate Date: Fri, 16 Jun 2017 16:03:51 +0200 Message-Id: <1497621833-9942-2-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497621833-9942-1-git-send-email-benjamin.gaignard@linaro.org> References: <1497621833-9942-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 "strut 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 Fri Jun 16 14:03:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 105747 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp1321304qgd; Fri, 16 Jun 2017 07:05:22 -0700 (PDT) X-Received: by 10.99.105.74 with SMTP id e71mr11398669pgc.51.1497621922716; Fri, 16 Jun 2017 07:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497621922; cv=none; d=google.com; s=arc-20160816; b=zPpK1SysinRGXLlm8ysK1xLxC3ViMWTGCORBZUo1IeKCUBcgBKBGqHGjzur5bQ/jKF PbPBoUNeJIjAmulTZ2CxPz2iZM6GXFoHm28/1MqjCN4Q5DbU89ecqdistsf7ZyuUmHY6 ocjYx9bJZvkocoQV7l3dZGFH/itc/RUn36KHmtzg2GIIOHs/g4JBCN0+xmfnG1HTWv2B M2B0lm67r6D1eIgHulilk0PcX+RRwlEk6cfXaJFw0Sa0YiVuMBGO00J5A5QfPS6upuJ8 1FquspsLm3qD8LnRYPsdjdP5tqNZqD2rEHfCsY2Zjs1GmRUX9FnwSa8FiuA/5gt5j7ip Rd5w== 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=+ObfvECF1k7XByKeVBvD2P7FgdaZ9VPCnw0TWa/BRZ8=; b=oaseLfWFA2U5WS5MRPCBQOqY6Rv7cYT6B6Gypfz5N1tlqMaQ0glpnF11WNkgBZE3zV n/MigMJ3uu/uxfuenMFOZHTLiDzxJ2nZw6VtMtOIcA9AnXJCqJcqA7X0aRSKRoPuzySp a84HfyvgFuLvmH4v0+sOl+HYg0SAr2oRIdrKdfYJL/R+SPKsy55NsTx0dNmg0VAVXFeY 8sKbYdoOhqLC+SOfZdwEgN9nQzS2u7mGgb7Ca7JMXsd/wCq5rA4bXieEoeYh9tQitWcy TXzFhPl9zwDw7v8nR3YRAzBGMjYE3Z8pv2bnCB2zhBB+03xUZ+KJbBWV2xWOCO8YiTvB ztbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=Ndz5l6gK; 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 f192si2049730pgc.179.2017.06.16.07.05.22; Fri, 16 Jun 2017 07:05:22 -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=Ndz5l6gK; 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 S1754062AbdFPOFJ (ORCPT + 25 others); Fri, 16 Jun 2017 10:05:09 -0400 Received: from mail-wr0-f169.google.com ([209.85.128.169]:34973 "EHLO mail-wr0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753101AbdFPOEy (ORCPT ); Fri, 16 Jun 2017 10:04:54 -0400 Received: by mail-wr0-f169.google.com with SMTP id q97so38997473wrb.2 for ; Fri, 16 Jun 2017 07:04:53 -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=+ObfvECF1k7XByKeVBvD2P7FgdaZ9VPCnw0TWa/BRZ8=; b=Ndz5l6gKHqlYo8kehEGzHK67fXKbbl9uI8gJ2FihrG7wbA8iBPRAVM4jnOaIXR4yJ7 bjzpIuC5JmoNDxJHYPa8w6jTRSFLX51Id3k00mg+rRsrIK3FzFS+x07SHv2g/oYCIDqR FEDiiY/0yz2EOnPIrEdNO0UtomyHIzJyJTd7E= 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=+ObfvECF1k7XByKeVBvD2P7FgdaZ9VPCnw0TWa/BRZ8=; b=pcI6b+FQTvpk+qyUhFl9zmpUeOQjsJT/V4dpCc58s0mxPwzFNzbyH0rKEmWhybhW8K bqncoWpTA8aYowyU+i7lSXnbW/bMM68JUOzci8UsWbpss75Wo+lJzMFBItVmdQ+aq8OA +3sCXrubJDrGpsL0ApVVJFKtyYcP0ZkqDsg2nsSr0o/Cxi091KSWqZM6bW9iWZqonk8J juHTEPaX3jkNG4gzRJoSA5+aDbW1LwSEg2Y9a28OApUAnV2MC1zceoX22Y6rG0lj5GbF zwXUnlLa5TjB8oA7gyTDGz4A4/dOBOvd4PVtwwF0CYFbEV56rFethGbZTW88KcIe5mGp 44WQ== X-Gm-Message-State: AKS2vOylRY8czSzGKNLG2Yw6R99E3eBoQOxgDW+0jqGadm5Th1hhj94K hJm7qS8s+RozStc7 X-Received: by 10.223.142.202 with SMTP id q68mr7063392wrb.25.1497621893061; Fri, 16 Jun 2017 07:04:53 -0700 (PDT) Received: from lmenx321.st.com. ([80.214.78.131]) by smtp.gmail.com with ESMTPSA id h12sm1883277wrc.43.2017.06.16.07.04.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Jun 2017 07:04:52 -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 2/3] tools: timer: add test to check y2038/2106 bug Date: Fri, 16 Jun 2017 16:03:52 +0200 Message-Id: <1497621833-9942-3-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497621833-9942-1-git-send-email-benjamin.gaignard@linaro.org> References: <1497621833-9942-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 The goal of this test is to check if a RTC device correctly support dates after years 2038 or 2106. It set a date (1-1-2200) on RTC and read it back to be sure that the driver is working well. The same thing is done on alarm. Signed-off-by: Benjamin Gaignard --- tools/testing/selftests/timers/Makefile | 4 +- tools/testing/selftests/timers/rtctest-2038.c | 135 ++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/timers/rtctest-2038.c -- 1.9.1 diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile index 54481f1..7791f79 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile @@ -9,7 +9,8 @@ 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 rtctest_setdate + leapcrash set-tai set-2038 set-tz rtctest_setdate \ + rtctest-2038 include ../lib.mk @@ -29,4 +30,5 @@ run_destructive_tests: run_tests ./set-tz ./set-tai ./set-2038 + ./rtctest-2038 diff --git a/tools/testing/selftests/timers/rtctest-2038.c b/tools/testing/selftests/timers/rtctest-2038.c new file mode 100644 index 0000000..213b7ee --- /dev/null +++ b/tools/testing/selftests/timers/rtctest-2038.c @@ -0,0 +1,135 @@ +/* Real Time Clock Driver Test + * by: Benjamin Gaignard (benjamin.gaignard@linaro.org) + * + * To build + * gcc rtctest-2038.c -o rtctest-2038 + * + * 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_rtc[] = "/dev/rtc0"; + +int main(int argc, char **argv) +{ + int fd, retval; + struct rtc_time new, current; + const char *rtc = default_rtc; + + switch (argc) { + case 2: + rtc = argv[1]; + /* FALLTHROUGH */ + case 1: + break; + default: + fprintf(stderr, "usage: rtctest-2038 [rtcdev]\n"); + return 1; + } + + fprintf(stderr, "\nTest if RTC is robust for date after y2038/2106\n\n"); + + fd = open(rtc, O_RDONLY); + if (fd == -1) { + perror(rtc); + exit(errno); + } + + new.tm_year = 300; /* 2200 - 1900 */ + new.tm_mon = 0; + new.tm_mday = 1; + new.tm_hour = 0; + new.tm_min = 0; + new.tm_sec = 0; + + 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, "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); + + if (new.tm_year != current.tm_year || + new.tm_mon != current.tm_mon || + new.tm_mday != current.tm_mday || + new.tm_hour != current.tm_hour || + new.tm_min != current.tm_min || + new.tm_sec != current.tm_sec) { + fprintf(stderr, "\n\nSet Time test failed\n"); + close(fd); + return 1; + } + + new.tm_sec += 5; + + fprintf(stderr, "\nTest will set RTC alarm 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 alarm in RTC */ + retval = ioctl(fd, RTC_ALM_SET, &new); + 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); + } + + fprintf(stderr, "RTC alarm 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); + + if (new.tm_year != current.tm_year || + new.tm_mon != current.tm_mon || + new.tm_mday != current.tm_mday || + new.tm_hour != current.tm_hour || + new.tm_min != current.tm_min || + new.tm_sec != current.tm_sec) { + fprintf(stderr, "\n\nSet alarm test failed\n"); + close(fd); + return 1; + } + + fprintf(stderr, "\nTest complete\n"); + close(fd); + return 0; +} From patchwork Fri Jun 16 14:03:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 105748 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp1321315qgd; Fri, 16 Jun 2017 07:05:23 -0700 (PDT) X-Received: by 10.84.231.194 with SMTP id g2mr13031679pln.34.1497621923534; Fri, 16 Jun 2017 07:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497621923; cv=none; d=google.com; s=arc-20160816; b=EQ9sxHASEMknhe/IU9zBD14UlOu/EXA62eBxlKc0+mGCXrS9lzrIJPkNMmfUPN7S0d ErkglKPROQ4S6J8FL8zOtVIYi27p7H7oEFdXuI7xCnBagUe3CkGwMOc/KS+TIarmHk6S tZM9A/I05CUtFOs0yCUpXi+2KgeyuJrs5KhY9TeZu2rpKfcWCWU59jTZ9Fm6N3N35MzP f/0S0ZibJ7LSaRlZJBTo9O+hKL2dHAVtpyuFecbnYJe5Sdt6ag/vliqTV3YityhqTMbC E5u7RC/HugJNUcqNbpea7BbjRxIoHgpgCpS7qLglkgoT8aJBvxv775BLTQwVL2zbuntq jTfQ== 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=Pmp86WE71VCG0xAL+4P23X8e6KOwOfaABNMuBuupcYc=; b=BNUzhj7t8/Xq1DjAOif+N2EM+vE8vwLfffgAd0SAeaByv3sTS6WrmtJrQHi4YmRPoQ AjAaqdwaUewb0m0m8cmb+JPmVVCEIswpG0y+K0Ugf8OQ+kVO9tj+gU1z85ib4XWPAfyM j5+9MbsZZbK5ySRolUAdpSZa5+yTBYkXfiMfGr2eSZJB/n6yY4D6yvZ+HNW8KLvV0JHK yfGfXfFYd2biVy06Amz4QbIc0/to/bSAzkVEJuJ90lVGp2W+9/knxUaJid1vwY2vvnDe FVFn7KD97HcPmtKIEYXHfEg2ewc81h2Pjbqu/kzuOrkAa7LJoGawR3eVwMyhe6A3jkT7 8q/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=OZ3jR2eY; 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 f192si2049730pgc.179.2017.06.16.07.05.23; Fri, 16 Jun 2017 07:05:23 -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=OZ3jR2eY; 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 S1754048AbdFPOFI (ORCPT + 25 others); Fri, 16 Jun 2017 10:05:08 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:35376 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753891AbdFPOFG (ORCPT ); Fri, 16 Jun 2017 10:05:06 -0400 Received: by mail-wm0-f51.google.com with SMTP id x70so27003092wme.0 for ; Fri, 16 Jun 2017 07:04:55 -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=Pmp86WE71VCG0xAL+4P23X8e6KOwOfaABNMuBuupcYc=; b=OZ3jR2eYEtsrW7RAs/1/beU8SmUz3iA7p9hQ6KRVXMp0/pV3n/Pe12PZvEeNVIDHQn 2MHNJlCVEu+pbZimX/u/CFkvnaucJzsQOEvJATQ1ifOrBfeK8iDO3Ki+bQM4uS8dnUAb VTtSFP2TtrsAubmMoCEcuaxWd+zc1fuPBaEOw= 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=Pmp86WE71VCG0xAL+4P23X8e6KOwOfaABNMuBuupcYc=; b=RyeH/5QolGGRX7uaSZgO8qIEfrcJ6Ul6UFCJ4pQIWLIgXLCAsKxtjkBU+vx0IPHj2N h9PATy6qzRyPtdTf0u8wJ6JG2SYetR9hdD766it4F2GTNpomcBIEdgD4VtiWVxI8t0kL 1VzJeDmYqd3weoCwP0hwMhcf5CW2+Uyi0saK6eOGoPWLjZwSStxD6HtooKP5fth/+Mfu 0dVmNM6COiZVt21weyaTSMVxbjd6NzOYVlGlTPXjrcCv+0IbbhEn8Gxxe5pB0YPHFt5Q g1vh965NKq2i/7NPDdc4JwwO/GBs+xQmCOlohuh6FmYeCZVW1Wm3Ybr2vwQGUGv3a1lc GWhA== X-Gm-Message-State: AKS2vOz9LUjAYw6xEj0Wyd3ZWlEO/rp4s8ZpyNb7rCyjQLAVBRLClr2b K6e9Mtq1l0gP9Zhk X-Received: by 10.28.23.4 with SMTP id 4mr7663744wmx.119.1497621894966; Fri, 16 Jun 2017 07:04:54 -0700 (PDT) Received: from lmenx321.st.com. ([80.214.78.131]) by smtp.gmail.com with ESMTPSA id h12sm1883277wrc.43.2017.06.16.07.04.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Jun 2017 07:04:54 -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 3/3] rtc: st-lpc: make it robust against y2038/2106 bug Date: Fri, 16 Jun 2017 16:03:53 +0200 Message-Id: <1497621833-9942-4-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497621833-9942-1-git-send-email-benjamin.gaignard@linaro.org> References: <1497621833-9942-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 --- drivers/rtc/rtc-st-lpc.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) -- 1.9.1 Acked-by: Patrice Chotard 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)