Skip to content
Commit bf99f310 authored by Andy Ross's avatar Andy Ross Committed by Anas Nashif
Browse files

kernel/timeout: Correctly clamp z_clock_set_timeout() argument



This function would correctly suppress attempts to set timeouts that
were too soon for the driver or farther out than what was already set,
but when it actually set the timeout it would use the requested value
and not clamp it to the minimum of it and the current timeout
expiration, leading to "too-long" timeouts being set at the driver.

In uniprocessor configurations, that turns out to have been benign
because something else would always come back along when timeout state
changed and fix the broken value before the expiration.

But in SMP, this opens up races.  For example, the idle thread on one
CPU can see that there are no active threads and schedule a maximum
value timeout at the same time as the other thread adds a new timeout
that expects a near-term expiration.  The broken code here would see
that the new timeout exists, decide that yes it needs to override, but
then set the K_TICKS_FOREVER value it got from the idle thread!

Signed-off-by: default avatarAndy Ross <andrew.j.ross@intel.com>
parent 4ae44dd7
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment