net: trickle: Do not initialize a work item from its handler

Initializing a work item from its handler will destroy the content of
the kernel structures used to process the work item. This can lead to a
system crash for example when the delayed work is being rescheduled when
the previous run is already queued for processing but not yet executed.

Fix this by initializing the work item once during trickle timer
creation and moving the logic, previously achieved by switching the work
handler, into the new work handler.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2021-04-26 15:31:17 +02:00 committed by Jukka Rissanen
commit afaf52af66
2 changed files with 21 additions and 11 deletions

View file

@ -60,6 +60,7 @@ struct net_trickle {
uint8_t c; /**< Consistency counter */
uint32_t Imax_abs; /**< Max interval size in ms (not doublings) */
bool double_to;
struct k_work_delayable timer;
net_trickle_cb_t cb; /**< Callback to be called when timer expires */