Fix-Point opened a new pull request, #22475:
URL: https://github.com/apache/nuttx/pull/22475

   ## Summary
   
   Extract the timespec validation duplicated across the timed-wait paths into 
one helper in `include/nuttx/clock.h`:
   
   `clock_timespec_validate()` checks `tv_sec >= 0 && tv_nsec >= 0 && tv_nsec < 
NSEC_PER_SEC`.
   
   It replaces the inline checks in `pthread_cond_clockwait()`, 
`clock_settime()`, `mq_timedreceive()`, `mq_timedsend()`, 
`nxsem_clockwait_slow()` and `nxsig_clockwait()`.
   
   This also fixes a bug in `nxsem_clockwait_slow()`: a negative 
`abstime->tv_sec` (for example -1) was previously accepted, since only 
`tv_nsec` was validated. The POSIX clock_nanosleep()/sem_timedwait() contract 
requires a non-negative `tv_sec`; the helper now rejects it. The same latent 
hole is closed in `nxsig_clockwait()`.
   
   ## Impact
   
   - `include/nuttx/clock.h` gains the helper plus a `#include <stdbool.h>` 
(the header previously had no bool users).
   - `sched/timer/timer_settime.c` is not touched: this tree does not have the 
local `timer_timespec_validate()` the upstream original refactored, so there is 
nothing to merge there.
   - The kernel builds are unaffected in size; behavior is unchanged except for 
the negative-`tv_sec` rejection.
   
   ## Testing
   
   Kernel build with `rv-virt:nsh` (only kernel .o targets, no app tree): all 
sched/clock, sched/semaphore, sched/signal and libs/libc targets compile with 
no errors (1118 kernel objects built). A matching app tree was not available 
locally, so the full image link was not exercised.
   
   checkpatch passes on the changed lines (the single clock_settime.c:69 report 
is pre-existing tree code, `const struct timeval zerodelta = {`, not introduced 
by this patch).
   
   The negative-`tv_sec` case is covered by the new helper's first condition; 
the other call sites get an identical check to the one they had before.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to