kernel: Fix double-list-removal corruption case in timeout handling
kernel: Fix double-list-removal corruption case in timeout handling

This fixes #8669, and is distressingly subtle for a one-line patch:

The list iteration code in _handle_expired_timeouts() would remove the
timeout from our (temporary -- the dlist header is on the stack of our
calling function) list of expired timeouts before invoking the
handler.  But sys_dlist_remove() only fixes up the containing list
pointers, leaving garbage in the node.  If the action of that handler
is to re-add the timeout (which is very common!) then that will then
try to remove it AGAIN from the same list.

Even then, the common case is that the expired list contains only one
item, so the result is a perfectly valid empty list that affects
nothing.  But if you have more than one, you get a corrupt cycle in
the iteration list and things get weird.

As it happens, there's no value in trying to remove this timeout from
the temporary list at all.  Just iterate over it naturally.

Really, this design is fragile: we shouldn't be reusing the list nodes
in struct _timeout for this purpose and should figure out some other
mechanism.  But this fix should be good for now.

Signed-off-by: Andy Ross <c70f9a6bf6ee0cd69c8af4ce5e6b131945769315@intel.com>

zephyrproject-rtos/zephyr,nashif/zephyr,ldts/zephyr,ldts/zephyr,Vudentz/zephyr,finikorg/zephyr,kraj/zephyr,explora26/zephyr,kraj/zephyr,galak/zephyr,Vudentz/zephyr,nashif/zephyr,finikorg/zephyr,ldts/zephyr,explora26/zephyr,galak/zephyr,GiulianoFranchetto/zephyr,punitvara/zephyr,Vudentz/zephyr,nashif/zephyr,GiulianoFranchetto/zephyr,punitvara/zephyr,zephyrproject-rtos/zephyr,explora26/zephyr,GiulianoFranchetto/zephyr,kraj/zephyr,explora26/zephyr,galak/zephyr,Vudentz/zephyr,ldts/zephyr,galak/zephyr,finikorg/zephyr,GiulianoFranchetto/zephyr,punitvara/zephyr,nashif/zephyr,finikorg/zephyr,explora26/zephyr,zephyrproject-rtos/zephyr,kraj/zephyr,zephyrproject-rtos/zephyr,Vudentz/zephyr,punitvara/zephyr,kraj/zephyr,GiulianoFranchetto/zephyr,zephyrproject-rtos/zephyr,ldts/zephyr,nashif/zephyr,Vudentz/zephyr,punitvara/zephyr,galak/zephyr,finikorg/zephyr