From aea9d35c4eab5b57bba26a01e0f9091ed2cdbcac Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 20 Apr 2020 10:52:25 -0500 Subject: [PATCH] kernel: fix runtime initialization of k_pipe object Runtime initialization failed to reset the lock field, causing problems when the pipe object is located on a stack and passed by reference to other code. Lacking an API for initializing a spinlock by itself use the idiom from _K_PIPE_INITIALIZER(). To simplify maintainability the initialization order is changed slightly to match the structure field declaration order. Signed-off-by: Peter Bigot --- kernel/pipes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/pipes.c b/kernel/pipes.c index efd2855c5ea..c6ae71555db 100644 --- a/kernel/pipes.c +++ b/kernel/pipes.c @@ -135,10 +135,11 @@ void k_pipe_init(struct k_pipe *pipe, unsigned char *buffer, size_t size) pipe->bytes_used = 0; pipe->read_index = 0; pipe->write_index = 0; - pipe->flags = 0; + pipe->lock = (struct k_spinlock){}; z_waitq_init(&pipe->wait_q.writers); z_waitq_init(&pipe->wait_q.readers); SYS_TRACING_OBJ_INIT(k_pipe, pipe); + pipe->flags = 0; z_object_init(pipe); }