This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 2b33168cc0fe497f56f6086a88764701eb2f0b6a Author: jiangtao16 <[email protected]> AuthorDate: Thu Aug 14 15:45:59 2025 +0800 sched/semaphore: Fix illegal abstime. Remove CONFIG_DEBUG_FEATURES to check illegal abstime. Signed-off-by: jiangtao16 <[email protected]> --- sched/semaphore/sem_clockwait.c | 69 ++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/sched/semaphore/sem_clockwait.c b/sched/semaphore/sem_clockwait.c index db4b1b6b708..f94ac81e809 100644 --- a/sched/semaphore/sem_clockwait.c +++ b/sched/semaphore/sem_clockwait.c @@ -94,7 +94,7 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid, { FAR struct tcb_s *rtcb = this_task(); irqstate_t flags; - int ret = ERROR; + int ret = -EINVAL; DEBUGASSERT(sem != NULL && abstime != NULL); DEBUGASSERT(up_interrupt_context() == false); @@ -107,55 +107,46 @@ int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid, * enabled while we are blocked waiting for the semaphore. */ - flags = enter_critical_section(); - - /* Try to take the semaphore without waiting. */ - - ret = nxsem_trywait(sem); - if (ret == OK) + if (abstime->tv_nsec >= 0 && abstime->tv_nsec < 1000000000) { - /* We got it! */ + flags = enter_critical_section(); - goto out; - } + /* Try to take the semaphore without waiting. */ - /* We will have to wait for the semaphore. Make sure that we were provided - * with a valid timeout. - */ + ret = nxsem_trywait(sem); + if (ret != OK) + { + /* We will have to wait for the semaphore. Make sure that + * we were provided with a valid timeout. + */ -#ifdef CONFIG_DEBUG_FEATURES - if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) - { - ret = -EINVAL; - goto out; - } -#endif + if (clockid == CLOCK_REALTIME) + { + wd_start_realtime(&rtcb->waitdog, abstime, + nxsem_timeout, (uintptr_t)rtcb); + } + else + { + wd_start_abstime(&rtcb->waitdog, abstime, + nxsem_timeout, (uintptr_t)rtcb); + } - if (clockid == CLOCK_REALTIME) - { - wd_start_realtime(&rtcb->waitdog, abstime, - nxsem_timeout, (uintptr_t)rtcb); - } - else - { - wd_start_abstime(&rtcb->waitdog, abstime, - nxsem_timeout, (uintptr_t)rtcb); - } + /* Now perform the blocking wait. If nxsem_wait() fails, the + * negated errno value will be returned below. + */ - /* Now perform the blocking wait. If nxsem_wait() fails, the - * negated errno value will be returned below. - */ + ret = nxsem_wait(sem); - ret = nxsem_wait(sem); + /* Stop the watchdog timer */ - /* Stop the watchdog timer */ + wd_cancel(&rtcb->waitdog); + } - wd_cancel(&rtcb->waitdog); + /* We can now restore interrupts and delete the watchdog */ - /* We can now restore interrupts and delete the watchdog */ + leave_critical_section(flags); + } -out: - leave_critical_section(flags); return ret; }
