kernel: timeout: Fix macro usage in next_timeout function
kernel: timeout: Fix macro usage in next_timeout function

The `next_timeout()` function used to call the `elapsed()` function
directly in the `MAX` macro call. This caused the `elapsed()` function
to be executed twice, with possible different results, if the system
clock incremented its value in a meantime.

As a result, the whole `MAX(0, to->dticks - elapsed()` expresion could
return an incorrect value of -1, which represents the K_FOREVER timeout.
This led to a stall in devices running tickless kernel (as observed on
nRF52840).

Signed-off-by: Robert Lubos <9d28997c6894a2d0321a7bb399169af7ce99b64e@nordicsemi.no>

nashif/zephyr,finikorg/zephyr,finikorg/zephyr,finikorg/zephyr,galak/zephyr,Vudentz/zephyr,zephyrproject-rtos/zephyr,Vudentz/zephyr,Vudentz/zephyr,nashif/zephyr,nashif/zephyr,zephyrproject-rtos/zephyr,finikorg/zephyr,finikorg/zephyr,galak/zephyr,zephyrproject-rtos/zephyr,galak/zephyr,nashif/zephyr,nashif/zephyr,galak/zephyr,zephyrproject-rtos/zephyr,zephyrproject-rtos/zephyr,Vudentz/zephyr,galak/zephyr,Vudentz/zephyr,Vudentz/zephyr