kernel: Clamp k_sleep() return value on overflow

k_sleep() returns a 32 bit count of milliseconds, as that was its
historical API.  But it now accepts a potentially 64 bit tick count as
an argument, leading to situations where an early wakeup will produce
sleep times that aren't representable.  Clamp this instead of
truncating to an arbitrary value.

Naive code will likely do the right thing with the large return (just
sleeping an extra round), and sophisticated apps can detect INT_MAX to
enable more elaborate retry logic.

(Also fixes a somewhat unfortunate puncutation error in the docs that
implied that it returns zero on early wakeup!)

Fixes: #84669

Signed-off-by: Andy Ross <andyross@google.com>
2 files changed