pkarashchenko commented on code in PR #7744: URL: https://github.com/apache/nuttx/pull/7744#discussion_r1036741844
########## arch/risc-v/src/common/riscv_mtimer.c: ########## @@ -290,7 +290,7 @@ static int riscv_mtimer_current(struct oneshot_lowerhalf_s *lower, struct riscv_mtimer_lowerhalf_s *priv = (struct riscv_mtimer_lowerhalf_s *)lower; uint64_t mtime = riscv_mtimer_get_mtime(priv); - uint64_t nsec = mtime * NSEC_PER_SEC / priv->freq; + uint64_t nsec = mtime * (NSEC_PER_SEC / priv->freq); Review Comment: Maybe it is better to ```suggestion uint64_t nsec = mtime / (priv->freq / USEC_PER_SEC) * NSEC_PER_USEC; ``` Instead? I'm worried about the possible precision drop. I'm not sure if what I wrote here is correct since I'm writing it from mobile, but you should catch the idea. I need to do some experiments for the frequency values that generate reminder after division with 1000. In general the proposed code is good to fix an overflow, but maybe there is a way to improve precision. -- 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: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org