Skip to content

Commit

Permalink
kernel: Apply const to k_pipe_put() parameter
Browse files Browse the repository at this point in the history
The pointer parameter 'data' in the function 'k_pipe_put()' ought to
use the const modifier as the contents of the buffer to which it
points never change. Internally, that const modifier is dropped as
both 'k_pipe_get()' and 'k_pipe_put()' share common code for copying
data; however 'k_pipe_put()' never takes a path that modifies those
contents.

Signed-off-by: Peter Mitsis <[email protected]>
  • Loading branch information
peter-mitsis authored and nashif committed Dec 15, 2023
1 parent b83b9be commit 4b2bf5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/zephyr/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -4968,7 +4968,7 @@ __syscall int k_pipe_alloc_init(struct k_pipe *pipe, size_t size);
* @retval -EAGAIN Waiting period timed out; between zero and @a min_xfer
* minus one data bytes were written.
*/
__syscall int k_pipe_put(struct k_pipe *pipe, void *data,
__syscall int k_pipe_put(struct k_pipe *pipe, const void *data,
size_t bytes_to_write, size_t *bytes_written,
size_t min_xfer, k_timeout_t timeout);

Expand Down
20 changes: 10 additions & 10 deletions kernel/pipes.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ static size_t pipe_write(struct k_pipe *pipe, sys_dlist_t *src_list,
return num_bytes_written;
}

int z_impl_k_pipe_put(struct k_pipe *pipe, void *data, size_t bytes_to_write,
size_t *bytes_written, size_t min_xfer,
k_timeout_t timeout)
int z_impl_k_pipe_put(struct k_pipe *pipe, const void *data,
size_t bytes_to_write, size_t *bytes_written,
size_t min_xfer, k_timeout_t timeout)
{
struct _pipe_desc pipe_desc[2];
struct _pipe_desc isr_desc;
Expand Down Expand Up @@ -445,7 +445,7 @@ int z_impl_k_pipe_put(struct k_pipe *pipe, void *data, size_t bytes_to_write,

src_desc = k_is_in_isr() ? &isr_desc : &_current->pipe_desc;

src_desc->buffer = data;
src_desc->buffer = (unsigned char *)data;
src_desc->bytes_to_xfer = bytes_to_write;
src_desc->thread = _current;
sys_dlist_append(&src_list, &src_desc->node);
Expand Down Expand Up @@ -513,17 +513,17 @@ int z_impl_k_pipe_put(struct k_pipe *pipe, void *data, size_t bytes_to_write,
}

#ifdef CONFIG_USERSPACE
int z_vrfy_k_pipe_put(struct k_pipe *pipe, void *data, size_t bytes_to_write,
size_t *bytes_written, size_t min_xfer,
k_timeout_t timeout)
int z_vrfy_k_pipe_put(struct k_pipe *pipe, const void *data,
size_t bytes_to_write, size_t *bytes_written,
size_t min_xfer, k_timeout_t timeout)
{
K_OOPS(K_SYSCALL_OBJ(pipe, K_OBJ_PIPE));
K_OOPS(K_SYSCALL_MEMORY_WRITE(bytes_written, sizeof(*bytes_written)));
K_OOPS(K_SYSCALL_MEMORY_READ((void *)data, bytes_to_write));

return z_impl_k_pipe_put((struct k_pipe *)pipe, (void *)data,
bytes_to_write, bytes_written, min_xfer,
timeout);
return z_impl_k_pipe_put((struct k_pipe *)pipe, data,
bytes_to_write, bytes_written, min_xfer,
timeout);
}
#include <syscalls/k_pipe_put_mrsh.c>
#endif
Expand Down

0 comments on commit 4b2bf5a

Please sign in to comment.