Skip to content

rtc: hibvt: do not set the clock to 1970 from a counter that lost power - #80

Merged
openipc-ai merged 1 commit into
hisilicon-hi3516cv500from
rtc/hibvt-low-voltage-hisilicon-hi3516cv500
Oct 20, 2026
Merged

openipc-ai merged 1 commit into
hisilicon-hi3516cv500from
rtc/hibvt-low-voltage-hisilicon-hi3516cv500

Conversation

@openipc-ai

@openipc-ai openipc-ai commented Oct 13, 2026 •

Copy link
Copy Markdown

Port of #79 (hisilicon-hi3516ev200) to hisilicon-hi3516cv500. Read #79 for the analysis and the hardware results.

This branch's rtc-hibvt.c has the same two defects:

  • A counter that lost power reads as 1970, and hctosys applies it.
  • The low-voltage flag is "cleared" by writing 1 to RTC_INT_CLR, which is the alarm bit.

The change is the same as in #79:

  • read_time() returns -EINVAL for a counter before 2000-01-01, and set_time() refuses the same range, so every time it accepts can be read back (Qodo's review point).
  • The flag is cleared with LV_INT_MASK.
  • The flag is not used to judge the time, or reported. On a hi3516ev300 it stays set with a fresh cell that keeps the time (see rtc: hibvt: do not set the clock to 1970 from a counter that lost power #79).

Verification

@openipc-ai

Copy link
Copy Markdown
Author

/review

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Dates before 2000 cannot be read back ✓ Resolved
Description
hibvt_rtc_read_time() rejects every timestamp before 2000, while hibvt_rtc_set_time() accepts
and writes those dates without a matching lower bound. Setting a valid date such as 1999-12-31
therefore succeeds, but the next read returns -EINVAL, including reads made by userspace and
boot-time clock synchronization.
Code

drivers/rtc/rtc-hibvt.c[R276-277]

+	if (seconds < RTC_MIN_VALID_SEC)
+		return -EINVAL;
Evidence
The setter converts a requested time to seconds and writes its day count without a 2000 minimum. The
new read-side comparison rejects that same counter value, and the RTC core propagates the read error
to callers.

drivers/rtc/rtc-hibvt.c[276-281]
drivers/rtc/rtc-hibvt.c[286-303]
drivers/rtc/interface.c[43-73]
drivers/rtc/hctosys.c[30-48]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The RTC accepts dates before 2000 when setting the time but rejects them on readback.
## Fix Focus Areas
- drivers/rtc/rtc-hibvt.c[272-277]
- drivers/rtc/rtc-hibvt.c[286-303]
## Recommended Fix
Reject only a counter state that identifies an unset RTC, or enforce the same documented minimum when setting the time so that every accepted value remains readable.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can open the rule or relationship behind a finding in one click

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@openipc-ai

Copy link
Copy Markdown
Author

/review

Comment thread drivers/rtc/rtc-hibvt.c
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 200a92d

Port of the hisilicon-hi3516ev200 fix. This branch has the same driver:
a counter that lost power reads as 1970 and hctosys applies it, and
the low-voltage flag is "cleared" by writing 1 to RTC_INT_CLR, which is
the alarm bit.

- read_time() returns -EINVAL for a counter before 2000-01-01, and
  set_time() refuses the same range, so every time it accepts can be
  read back.
- Clear the low-voltage flag with LV_INT_MASK.

The flag itself does not decide validity: on a hi3516ev300 it stays
set with a fresh backup cell that keeps the time through a power cut.
@openipc-ai
openipc-ai force-pushed the rtc/hibvt-low-voltage-hisilicon-hi3516cv500 branch from 200a92d to 03f903e Compare October 20, 2026 11:15
@openipc-ai openipc-ai changed the title rtc: hibvt: report a flat backup cell, and do not set the clock to 1970 rtc: hibvt: do not set the clock to 1970 from a counter that lost power Oct 20, 2026
@openipc-ai
openipc-ai merged commit 89f5524 into hisilicon-hi3516cv500 Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant