All of lore.kernel.org
 help / color / mirror / Atom feed
From: Grant Feng <von81@163.com>
To: von81@163.com, a.zummo@towertech.it,
	alexandre.belloni@bootlin.com, linux-rtc@vger.kernel.org
Subject: [PATCH] rtc: interface:: 1969-12-31T23:59:59 is set as rtc_time if rtc_time is invalid in __rtc_read_time
Date: Sat,  1 Aug 2020 19:20:07 +0800	[thread overview]
Message-ID: <20200801112007.2148-1-von81@163.com> (raw)

1969-12-31T23:59:59 is an error more clear than Invalid argument

For example, when the RTC clock is not set, it will print a kernel
error log every time someone tries to read the clock:
        ~ # hwclock -r
        hwclock: RTC_RD_TIME: Invalid argument

It's clear and easy to understand what happened if print
1969-12-31T23:59:59 in this situation:
        ~ # hwclock -r
        Wed Dec 31 23:59:59 1969  0.000000 seconds

Signed-off-by: Grant Feng <von81@163.com>
---
 drivers/rtc/interface.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 794a4f036b99..e6b3f4163565 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -101,8 +101,20 @@ static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
 		rtc_add_offset(rtc, tm);
 
 		err = rtc_valid_tm(tm);
-		if (err < 0)
+		if (err < 0) {
 			dev_dbg(&rtc->dev, "read_time: rtc_time isn't valid\n");
+
+			tm->tm_sec = 59;
+			tm->tm_min = 59;
+			tm->tm_hour = 23;
+			tm->tm_mday = 31;
+			tm->tm_mon = 11;
+			tm->tm_year = 69;
+			tm->tm_wday = 3;
+			tm->tm_yday = 365;
+			tm->tm_isdst = 0;
+		}
+		err = 0;
 	}
 	return err;
 }
-- 
2.17.1



             reply	other threads:[~2020-08-01 11:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-01 11:20 Grant Feng [this message]
2020-08-01 13:28 ` [PATCH] rtc: interface:: 1969-12-31T23:59:59 is set as rtc_time if rtc_time is invalid in __rtc_read_time Alexandre Belloni
2020-08-02  6:51   ` [PATCH] rtc: interface^ " Grant Feng
2020-08-02 13:04     ` Alexandre Belloni
2020-08-02 13:35       ` Grant Feng
2020-08-03  3:07       ` Grant Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200801112007.2148-1-von81@163.com \
    --to=von81@163.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-rtc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.