Browse Source

kernel: Compare pointers with NULL in while statements

Make while statement using pointers explicitly check whether
the value is NULL or not.

The C standard does not say that the null pointer is the same
as the pointer to memory address 0 and because of this is a good
practice always compare with the macro NULL.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
pull/10072/head
Flavio Ceolin 7 years ago committed by Anas Nashif
parent
commit
c806ac3d36
  1. 6
      kernel/pipes.c
  2. 3
      kernel/queue.c
  3. 2
      kernel/sys_clock.c
  4. 4
      kernel/thread.c

6
kernel/pipes.c

@ -477,7 +477,7 @@ int _k_pipe_put_internal(struct k_pipe *pipe, struct k_pipe_async *async_desc,
struct k_thread *thread = (struct k_thread *) struct k_thread *thread = (struct k_thread *)
sys_dlist_get(&xfer_list); sys_dlist_get(&xfer_list);
while (thread) { while (thread != NULL) {
desc = (struct k_pipe_desc *)thread->base.swap_data; desc = (struct k_pipe_desc *)thread->base.swap_data;
bytes_copied = pipe_xfer(desc->buffer, desc->bytes_to_xfer, bytes_copied = pipe_xfer(desc->buffer, desc->bytes_to_xfer,
data + num_bytes_written, data + num_bytes_written,
@ -625,7 +625,7 @@ int _impl_k_pipe_get(struct k_pipe *pipe, void *data, size_t bytes_to_read,
struct k_thread *thread = (struct k_thread *) struct k_thread *thread = (struct k_thread *)
sys_dlist_get(&xfer_list); sys_dlist_get(&xfer_list);
while (thread && (num_bytes_read < bytes_to_read)) { while ((thread != NULL) && (num_bytes_read < bytes_to_read)) {
desc = (struct k_pipe_desc *)thread->base.swap_data; desc = (struct k_pipe_desc *)thread->base.swap_data;
bytes_copied = pipe_xfer(data + num_bytes_read, bytes_copied = pipe_xfer(data + num_bytes_read,
bytes_to_read - num_bytes_read, bytes_to_read - num_bytes_read,
@ -665,7 +665,7 @@ int _impl_k_pipe_get(struct k_pipe *pipe, void *data, size_t bytes_to_read,
* into the pipe's circular buffer. * into the pipe's circular buffer.
*/ */
while (thread) { while (thread != NULL) {
desc = (struct k_pipe_desc *)thread->base.swap_data; desc = (struct k_pipe_desc *)thread->base.swap_data;
bytes_copied = pipe_buffer_put(pipe, desc->buffer, bytes_copied = pipe_buffer_put(pipe, desc->buffer,
desc->bytes_to_xfer); desc->bytes_to_xfer);

3
kernel/queue.c

@ -237,7 +237,8 @@ void k_queue_append_list(struct k_queue *queue, void *head, void *tail)
#if !defined(CONFIG_POLL) #if !defined(CONFIG_POLL)
struct k_thread *thread; struct k_thread *thread;
while (head && ((thread = _unpend_first_thread(&queue->wait_q)))) { while ((head != NULL) &&
(thread = _unpend_first_thread(&queue->wait_q))) {
prepare_thread_to_run(thread, head); prepare_thread_to_run(thread, head);
head = *(void **)head; head = *(void **)head;
} }

2
kernel/sys_clock.c

@ -196,7 +196,7 @@ static inline void handle_timeouts(s32_t ticks)
* prohibited. * prohibited.
*/ */
while (next) { while (next != NULL) {
/* /*
* In the case where ticks number is greater than the first * In the case where ticks number is greater than the first

4
kernel/thread.c

@ -162,8 +162,8 @@ void _thread_monitor_exit(struct k_thread *thread)
struct k_thread *prev_thread; struct k_thread *prev_thread;
prev_thread = _kernel.threads; prev_thread = _kernel.threads;
while (prev_thread != NULL && while ((prev_thread != NULL) &&
thread != prev_thread->next_thread) { (thread != prev_thread->next_thread)) {
prev_thread = prev_thread->next_thread; prev_thread = prev_thread->next_thread;
} }
if (prev_thread != NULL) { if (prev_thread != NULL) {

Loading…
Cancel
Save