Browse Source

kernel: Explicitly comparing pointer with NULL

MISRA-C rule: 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
pull/10170/merge
Flavio Ceolin 7 years ago committed by Anas Nashif
parent
commit
ea716bf023
  1. 2
      include/logging/log_msg.h
  2. 4
      kernel/include/ksched.h
  3. 6
      kernel/include/timeout_q.h
  4. 2
      kernel/mem_slab.c
  5. 2
      kernel/mempool.c
  6. 4
      kernel/msg_q.c
  7. 2
      kernel/pipes.c
  8. 2
      kernel/sem.c
  9. 4
      kernel/stack.c
  10. 2
      kernel/thread.c
  11. 3
      kernel/userspace.c

2
include/logging/log_msg.h

@ -347,7 +347,7 @@ static inline struct log_msg *_log_msg_std_alloc(void) @@ -347,7 +347,7 @@ static inline struct log_msg *_log_msg_std_alloc(void)
{
struct log_msg *msg = (struct log_msg *)log_msg_chunk_alloc();
if (msg) {
if (msg != NULL) {
/* all fields reset to 0, reference counter to 1 */
msg->hdr.ref_cnt = 1;
msg->hdr.params.raw = 0;

4
kernel/include/ksched.h

@ -240,7 +240,7 @@ static inline void _ready_one_thread(_wait_q_t *wq) @@ -240,7 +240,7 @@ static inline void _ready_one_thread(_wait_q_t *wq)
{
struct k_thread *th = _unpend_first_thread(wq);
if (th) {
if (th != NULL) {
_ready_thread(th);
}
}
@ -285,7 +285,7 @@ static inline struct k_thread *_unpend1_no_timeout(_wait_q_t *wait_q) @@ -285,7 +285,7 @@ static inline struct k_thread *_unpend1_no_timeout(_wait_q_t *wait_q)
{
struct k_thread *thread = _find_first_thread_to_unpend(wait_q, NULL);
if (thread) {
if (thread != NULL) {
_unpend_thread_no_timeout(thread);
}

6
kernel/include/timeout_q.h

@ -68,7 +68,7 @@ _init_thread_timeout(struct _thread_base *thread_base) @@ -68,7 +68,7 @@ _init_thread_timeout(struct _thread_base *thread_base)
static inline void _unpend_thread_timing_out(struct k_thread *thread,
struct _timeout *timeout_obj)
{
if (timeout_obj->wait_q) {
if (timeout_obj->wait_q != NULL) {
_unpend_thread_no_timeout(thread);
thread->base.timeout.wait_q = NULL;
}
@ -88,14 +88,14 @@ static inline void _handle_one_expired_timeout(struct _timeout *timeout) @@ -88,14 +88,14 @@ static inline void _handle_one_expired_timeout(struct _timeout *timeout)
timeout->delta_ticks_from_prev = _INACTIVE;
K_DEBUG("timeout %p\n", timeout);
if (thread) {
if (thread != NULL) {
_unpend_thread_timing_out(thread, timeout);
_mark_thread_as_started(thread);
_ready_thread(thread);
irq_unlock(key);
} else {
irq_unlock(key);
if (timeout->func) {
if (timeout->func != NULL) {
timeout->func(timeout);
}
}

2
kernel/mem_slab.c

@ -117,7 +117,7 @@ void k_mem_slab_free(struct k_mem_slab *slab, void **mem) @@ -117,7 +117,7 @@ void k_mem_slab_free(struct k_mem_slab *slab, void **mem)
int key = irq_lock();
struct k_thread *pending_thread = _unpend_first_thread(&slab->wait_q);
if (pending_thread) {
if (pending_thread != NULL) {
_set_thread_return_value_with_data(pending_thread, 0, *mem);
_ready_thread(pending_thread);
_reschedule(key);

2
kernel/mempool.c

@ -209,7 +209,7 @@ void *z_thread_malloc(size_t size) @@ -209,7 +209,7 @@ void *z_thread_malloc(size_t size)
{
void *ret;
if (_current->resource_pool) {
if (_current->resource_pool != NULL) {
ret = k_mem_pool_malloc(_current->resource_pool, size);
} else {
ret = NULL;

4
kernel/msg_q.c

@ -76,7 +76,7 @@ int _impl_k_msgq_alloc_init(struct k_msgq *q, size_t msg_size, @@ -76,7 +76,7 @@ int _impl_k_msgq_alloc_init(struct k_msgq *q, size_t msg_size,
ret = -EINVAL;
} else {
buffer = z_thread_malloc(total_size);
if (buffer) {
if (buffer != NULL) {
k_msgq_init(q, buffer, msg_size, max_msgs);
q->flags = K_MSGQ_FLAG_ALLOC;
ret = 0;
@ -119,7 +119,7 @@ int _impl_k_msgq_put(struct k_msgq *q, void *data, s32_t timeout) @@ -119,7 +119,7 @@ int _impl_k_msgq_put(struct k_msgq *q, void *data, s32_t timeout)
if (q->used_msgs < q->max_msgs) {
/* message queue isn't full */
pending_thread = _unpend_first_thread(&q->wait_q);
if (pending_thread) {
if (pending_thread != NULL) {
/* give message to waiting thread */
(void)memcpy(pending_thread->base.swap_data, data,
q->msg_size);

2
kernel/pipes.c

@ -347,7 +347,7 @@ static bool pipe_xfer_prepare(sys_dlist_t *xfer_list, @@ -347,7 +347,7 @@ static bool pipe_xfer_prepare(sys_dlist_t *xfer_list,
sys_dlist_init(xfer_list);
num_bytes = 0;
while ((thread = _waitq_head(wait_q))) {
while ((thread = _waitq_head(wait_q)) != NULL) {
desc = (struct k_pipe_desc *)thread->base.swap_data;
num_bytes += desc->bytes_to_xfer;

2
kernel/sem.c

@ -101,7 +101,7 @@ static void do_sem_give(struct k_sem *sem) @@ -101,7 +101,7 @@ static void do_sem_give(struct k_sem *sem)
{
struct k_thread *thread = _unpend_first_thread(&sem->wait_q);
if (thread) {
if (thread != NULL) {
_ready_thread(thread);
_set_thread_return_value(thread, 0);
} else {

4
kernel/stack.c

@ -62,7 +62,7 @@ int _impl_k_stack_alloc_init(struct k_stack *stack, unsigned int num_entries) @@ -62,7 +62,7 @@ int _impl_k_stack_alloc_init(struct k_stack *stack, unsigned int num_entries)
int ret;
buffer = z_thread_malloc(num_entries);
if (buffer) {
if (buffer != NULL) {
k_stack_init(stack, buffer, num_entries);
stack->flags = K_STACK_FLAG_ALLOC;
ret = 0;
@ -105,7 +105,7 @@ void _impl_k_stack_push(struct k_stack *stack, u32_t data) @@ -105,7 +105,7 @@ void _impl_k_stack_push(struct k_stack *stack, u32_t data)
first_pending_thread = _unpend_first_thread(&stack->wait_q);
if (first_pending_thread) {
if (first_pending_thread != NULL) {
_ready_thread(first_pending_thread);
_set_thread_return_value_with_data(first_pending_thread,

2
kernel/thread.c

@ -394,7 +394,7 @@ void _setup_new_thread(struct k_thread *new_thread, @@ -394,7 +394,7 @@ void _setup_new_thread(struct k_thread *new_thread,
#endif
#ifdef CONFIG_USERSPACE
/* New threads inherit any memory domain membership by the parent */
if (_current->mem_domain_info.mem_domain) {
if (_current->mem_domain_info.mem_domain != NULL) {
k_mem_domain_add_thread(_current->mem_domain_info.mem_domain,
new_thread);
}

3
kernel/userspace.c

@ -513,7 +513,8 @@ void k_object_access_all_grant(void *object) @@ -513,7 +513,8 @@ void k_object_access_all_grant(void *object)
int _k_object_validate(struct _k_object *ko, enum k_objects otype,
enum _obj_init_check init)
{
if (unlikely(!ko || (otype != K_OBJ_ANY && ko->type != otype))) {
if (unlikely((ko == NULL) ||
(otype != K_OBJ_ANY && ko->type != otype))) {
return -EBADF;
}

Loading…
Cancel
Save