Repository navigation
Conversation
| * already check dev the same way. | ||
| */ | ||
| if (priv == NULL || msgs == NULL) { | ||
| i2cinfo("i2c dev/msgs is NULL\n"); |
There was a problem hiding this comment.
- We can use error or warning in this case instead of info. @eunwoo-nam Could you guide him which one is proper?
- We can find the reason why this function returns ERROR by null priv or by null msgs. Let's print the value of both for easiler debugging.
There was a problem hiding this comment.
@sunghan-chang @eunwoo-nam
I'd prefer i2cerr : a NULL dev / msgs is caller misuse and we return ERROR , so error level fits. But this file defines i2cinfo as an empty macro, and i2cerr also requires CONFIG_DEBUG_I2C_ERROR to print, so neither shows by default. Would lowsyslog(LOG_ERR, ...) be acceptable instead?
| DEBUGASSERT(lower != NULL && rtctime != NULL); | ||
| if (lower == NULL || rtctime == NULL) { |
There was a problem hiding this comment.
@eunwoo-nam Do we need to keep both line 211 and line 212?
There was a problem hiding this comment.
These two checks are redundant, and with assertions enabled DEBUGASSERT panics before reaching -EINVAL . armino_settime() (line 255) uses only the if check. Can we drop DEBUGASSERT and keep just the if ?
mangeshraut712
left a comment
There was a problem hiding this comment.
Reviewed against the merge-base (278667a9; the branch is 35 commits behind master, but the four files are self-contained). Not an approval — that's for a maintainer.
Went through all four files. Everything checks out; the RTC boot hang is the headline and it's a real one.
RTC: the boot hang is live, not theoretical
On master, ana_rtc_hw_init() is:
while (1) {
if (aon_pmu_hal_rtc_tick_l_get() < s_ana_rtc_base_tick)
break;
}aon_pmu_hal_rtc_tick_l_get() returns uint32_t and s_ana_rtc_base_tick is set at l.880 from the same call just above — so if the 32K clock hasn't ticked yet and the hardware reads 0, base == 0 and tick < 0 is never true for unsigned. That's an unbounded loop on the boot path. Your two-part fix is right:
base == 0→ skip the wait entirely, with a warning. Correct: there's nothing to wait for if the base is zero.- Otherwise, bound by iteration count (
ANA_RTC_TICK_RESET_RETRY_MAX = 100000), not by a tick-based timeout. Your comment explains why that's the right choice — a stalled 32K clock would freeze any tick-derived deadline, so only a loop count is meaningful here. Good reasoning; that's the detail a naive fix would get wrong.
PM thread (bk_pm_thread.c) — four correct changes
return BK_FAIL→breakonregister rxd_wk_alarmfailure: it's inside the messageswitch, sobreakexits the switch and the loop keeps running.retis already!= BK_OKfrom the check, so the failure is still reported upward — the thread just doesn't die. Right.else { rtos_delay_milliseconds(10); }on pop failure: onmastera failedrtos_pop_from_queuefell straight back into the loop with no delay, i.e. a busy-spin at thread priority. The backoff fixes that.- Re-init guard
if (s_queue != NULL) return BK_OKprevents a secondpm_thread_main()from leaking a queue. - Thread-create failure now
rtos_deinit_queue(&s_queue)and NULLs it — onmasterthe queue leaked.
I checked the asymmetry on the two failure paths, and it's correct
Queue-create failure does s_queue = NULL with no deinit; thread-create failure does call deinit. That looks inconsistent but it's right: rtos_init_queue (rtos_pub.c:443) does mq_open first and returns kGeneralErr on failure before any kmm_malloc, so there's nothing to tear down. And rtos_deinit_queue (rtos_pub.c:548) early-returns on *queue == NULL, so it's safe where you do call it.
armino_i2c.c / armino_rtc_lowerhalf.c
Both match the description. I2C_TRANSFER() has no upstream check so the callee validating priv/msgs is right, and setaddress()/setclock() already do the same. The -EINVAL on lower == NULL || rtctime == NULL in rdtime/settime closes the RTC_RD_TIME/RTC_SET_TIME NULL-ioctl path.
Nice PR — the RTC fix on its own is worth merging, and the write-up makes each change easy to follow.
RTC_RD_TIME / RTC_SET_TIME forward the caller-supplied ioctl argument to the lower half without validation, and I2C_TRANSFER() passes dev and msgs through unchecked. - armino_rdtime() only had a DEBUGASSERT before calling gmtime_r(), and armino_settime() called mktime() directly, so ioctl(fd, RTC_RD_TIME, 0) writes through a NULL pointer. - armino_i2c_transfer() dereferenced msgs and priv before any check, while the sibling ops setaddress() and setclock() already validate dev. Return -EINVAL from the RTC ops and ERROR from armino_i2c_transfer() when the arguments are NULL. Valid callers are unaffected.
- bk_pm: do not start the PM worker when rtos_init_queue() fails, back off 10 ms on a pop error, and keep the thread alive when alarm registration fails. Previously a NULL queue made the worker spin forever, and an alarm error returned from the thread body. - RTC: bound the wait for the 32K tick reset in ana_rtc_hw_init() and skip it when s_ana_rtc_base_tick is 0. Both cases could hang the boot.
d6d9ffb to
b12a293
Compare
🤖 AI Code Review ·
|
Summary
Static analysis of the kernel reported hang and crash findings in the
BK7239n board support code and the ARMINO architecture layer. This PR
fixes the findings where an abnormal input, a resource failure or a
stalled clock turned a recoverable error into an infinite wait or a NULL
pointer access.
Changes
os/board/bk7239n
created, release the queue if thread creation fails, back off on a
pop error instead of spinning, and keep the thread alive when alarm
registration fails.
when the base tick is 0. Previously this could hang the boot.
os/arch/arm/src/armino
armino_rdtime() and armino_settime(). Both are reachable through
RTC_RD_TIME / RTC_SET_TIME with a NULL ioctl argument.
matching the checks already done by setaddress() and setclock().