From fd67ef3af94ab9221be7442fbc73f5a1ec892972 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Mon, 15 Sep 2025 14:33:06 +0800 Subject: [PATCH] assert: fix DEBUGASSERT recursive triggering Add head pointer checks in notifier_call_chain macros to prevent recursion into sched_lock() when assertions are triggered during early system startup. This avoids cascading DEBUGASSERT failures when the notifier head is empty or uninitialized. backtrace: DEBUGASSERT(rtcb && rtcb->lockcount < MAX_LOCK_COUNT); sched_lock() panic_notifier_call_chain _assert() arm64_fatal_handler Signed-off-by: hujun5 --- include/nuttx/notifier.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/include/nuttx/notifier.h b/include/nuttx/notifier.h index 9afe8457f39..cc847121bef 100644 --- a/include/nuttx/notifier.h +++ b/include/nuttx/notifier.h @@ -212,10 +212,12 @@ extern "C" do \ { \ FAR struct atomic_notifier_head *nh = (nhead); \ - irqstate_t flags; \ - flags = rspin_lock_irqsave_nopreempt(&nh->lock); \ - notifier_call_chain(nh->head, (val), (v), -1, NULL); \ - rspin_unlock_irqrestore_nopreempt(&nh->lock, flags); \ + if (nh != NULL && nh->head != NULL) \ + { \ + irqstate_t flags = rspin_lock_irqsave_nopreempt(&nh->lock); \ + notifier_call_chain(nh->head, (val), (v), -1, NULL); \ + rspin_unlock_irqrestore_nopreempt(&nh->lock, flags); \ + } \ } \ while(0) @@ -262,12 +264,15 @@ extern "C" do \ { \ FAR struct blocking_notifier_head *nh = (nhead); \ - if (nxmutex_lock(&nh->mutex) < 0) \ + if (nh != NULL && nh->head != NULL) \ { \ - break; \ + if (nxmutex_lock(&nh->mutex) < 0) \ + { \ + break; \ + } \ + notifier_call_chain(nh->head, (val), (v), -1, NULL); \ + nxmutex_unlock(&nh->mutex);\ } \ - notifier_call_chain(nh->head, (val), (v), -1, NULL); \ - nxmutex_unlock(&nh->mutex);\ } \ while(0)