Fix-Point commented on code in PR #22492:
URL: https://github.com/apache/nuttx/pull/22492#discussion_r4734290961


##########
sched/wqueue/kwork_queue.c:
##########
@@ -77,7 +77,7 @@ static int work_qqueue(FAR struct kwork_wqueue_s *wqueue,
   bool retimer;
 
   if (wqueue == NULL || work == NULL || worker == NULL ||
-      delay < 0 || delay > WDOG_MAX_DELAY)
+      (uint64_t)delay > WQUEUE_MAX_DELAY)

Review Comment:
   I kept the cast in the three delay-bound checks
   on purpose: it collapses the negative-delay rejection and the upper
   bound into a single comparison.
   
   `WDOG_MAX_DELAY` is `CLOCK_MAX >> 2` = a signed `int64_t`. Casting
   `delay` (a signed `clock_t`) to `uint64_t` first turns every negative
   value into a huge positive number that necessarily exceeds the limit,
   so
   
       (uint64_t)delay <= WDOG_MAX_DELAY
   
   rejects negative delays and oversized ones with one comparison instead
   of two (`delay >= 0 && delay <= WDOG_MAX_DELAY`). The same idiom is
   used in `wd_start_next()` (`(uint64_t)delay > 0 && ...`) and in
   `work_qqueue()` (`(uint64_t)delay > WQUEUE_MAX_DELAY`).
   
   The other comments are addressed: the redundant `(uint64_t)` casts in
   the `TICK2NSEC(...)` call sites are removed, and `delay` is now
   `clock_t` in `wd_timer_start()`/`wd_timer()`.



-- 
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