kernel: k_work: k_work_init() should initialize all fields
k_work_init() was not initializing all fields in the k_work struct.
Mainly, the atomic_clear_bit() function call was reading a possibly
uninitialized value, clearing a bit, and assigning it back to the
`flags` member. The `_reserved` member was never initialized.
With the struct now initialized with the _K_WORK_INITIALIZER() macro,
initialization is consistent regardless of how a `struct k_work` is
initialized.
This fixes the Valgrind issues found in #7478.
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
diff --git a/include/kernel.h b/include/kernel.h
index 865316c..d58f1a8 100644
--- a/include/kernel.h
+++ b/include/kernel.h
@@ -2584,8 +2584,7 @@
*/
static inline void k_work_init(struct k_work *work, k_work_handler_t handler)
{
- atomic_clear_bit(work->flags, K_WORK_STATE_PENDING);
- work->handler = handler;
+ *work = (struct k_work)_K_WORK_INITIALIZER(handler);
_k_object_init(work);
}