linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ladislav Michl <oss-lists@triops.cz>
To: linux-rtc@vger.kernel.org
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH] rtc: m41t80: Fix invalid alarm time
Date: Thu, 13 Apr 2023 14:46:42 +0200	[thread overview]
Message-ID: <ZDf5soNMNaI+VOId@lenoch> (raw)

From: Ladislav Michl <ladis@linux-mips.org>

When no alarm has been programmed on m41t80 chip, an error message is
printed during boot:

    rtc rtc0: invalid alarm value: 2023-4-12 45:85:85

Fix this by returning -1 instead of actual register values.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 NOTE: 
 This patch is shamelessly based on
 15d82d224987 ("rtc: sh: Fix invalid alarm warning for non-enabled alarm")
 so question arises whenever rtc core should'n handle !alrm->enabled
 case itself.

 drivers/rtc/rtc-m41t80.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 084ff1f07a82..678769847df6 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -572,15 +572,23 @@ static int m41t80_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	if (flags < 0)
 		return flags;
 
-	alrm->time.tm_sec  = bcd2bin(alarmvals[4] & 0x7f);
-	alrm->time.tm_min  = bcd2bin(alarmvals[3] & 0x7f);
-	alrm->time.tm_hour = bcd2bin(alarmvals[2] & 0x3f);
-	alrm->time.tm_mday = bcd2bin(alarmvals[1] & 0x3f);
-	alrm->time.tm_mon  = bcd2bin(alarmvals[0] & 0x3f) - 1;
-
 	alrm->enabled = !!(alarmvals[0] & M41T80_ALMON_AFE);
 	alrm->pending = (flags & M41T80_FLAGS_AF) && alrm->enabled;
 
+	if (alrm->enabled) {
+		alrm->time.tm_sec  = bcd2bin(alarmvals[4] & 0x7f);
+		alrm->time.tm_min  = bcd2bin(alarmvals[3] & 0x7f);
+		alrm->time.tm_hour = bcd2bin(alarmvals[2] & 0x3f);
+		alrm->time.tm_mday = bcd2bin(alarmvals[1] & 0x3f);
+		alrm->time.tm_mon  = bcd2bin(alarmvals[0] & 0x3f) - 1;
+	} else {
+		alrm->time.tm_sec  = -1;
+		alrm->time.tm_min  = -1;
+		alrm->time.tm_hour = -1;
+		alrm->time.tm_mday = -1;
+		alrm->time.tm_mon  = -1;
+	}
+
 	return 0;
 }
 
-- 
2.32.0


                 reply	other threads:[~2023-04-13 12:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=ZDf5soNMNaI+VOId@lenoch \
    --to=oss-lists@triops.cz \
    --cc=geert+renesas@glider.be \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).