From fb50c44d08057d2a804aea14e90738316f5f1f2f Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Tue, 6 Feb 2018 09:13:16 -0600 Subject: [PATCH] Fix various issues noted by Coverity --- libc/semaphore/sem_getvalue.c | 2 +- net/tcp/tcp_send_buffered.c | 2 +- net/tcp/tcp_wrbuffer.c | 11 +++++++++-- sched/mqueue/mq_rcvinternal.c | 2 +- sched/pthread/pthread_getschedparam.c | 22 ++++++++++++---------- sched/pthread/pthread_mutexconsistent.c | 2 +- sched/sched/sched_setscheduler.c | 1 + wireless/ieee802154/ieee802154_primitive.c | 11 ++++++++--- 8 files changed, 34 insertions(+), 19 deletions(-) diff --git a/libc/semaphore/sem_getvalue.c b/libc/semaphore/sem_getvalue.c index d6da1ba4bf..bde910f16e 100644 --- a/libc/semaphore/sem_getvalue.c +++ b/libc/semaphore/sem_getvalue.c @@ -77,7 +77,7 @@ int nxsem_getvalue(FAR sem_t *sem, FAR int *sval) { - if (sem && sval) + if (sem != NULL && sval != NULL) { *sval = sem->semcount; return OK; diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index b8463b0643..9c6073aa3c 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -1174,7 +1174,7 @@ int psock_tcp_cansend(FAR struct socket *psock) return -ENOTCONN; } - if (tcp_wrbuffer_test()) + if (tcp_wrbuffer_test() < 0) { return -EWOULDBLOCK; } diff --git a/net/tcp/tcp_wrbuffer.c b/net/tcp/tcp_wrbuffer.c index 643d990708..9cd8e798b3 100644 --- a/net/tcp/tcp_wrbuffer.c +++ b/net/tcp/tcp_wrbuffer.c @@ -211,8 +211,15 @@ void tcp_wrbuffer_release(FAR struct tcp_wrbuffer_s *wrb) int tcp_wrbuffer_test(void) { int val = 0; - nxsem_getvalue(&g_wrbuffer.sem, &val); - return val > 0 ? OK : ERROR; + int ret; + + ret = nxsem_getvalue(&g_wrbuffer.sem, &val); + if (ret >= 0) + { + ret = val > 0 ? OK : -ENOSPC; + } + + return ret; } #endif /* CONFIG_NET && CONFIG_NET_TCP && CONFIG_NET_TCP_WRITE_BUFFERS */ diff --git a/sched/mqueue/mq_rcvinternal.c b/sched/mqueue/mq_rcvinternal.c index 78479314ff..00ab85e373 100644 --- a/sched/mqueue/mq_rcvinternal.c +++ b/sched/mqueue/mq_rcvinternal.c @@ -302,7 +302,7 @@ ssize_t nxmq_do_receive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, * time the task is unblocked */ - DEBUGASSERT(btcb); + DEBUGASSERT(btcb != NULL); btcb->msgwaitq = NULL; msgq->nwaitnotfull--; diff --git a/sched/pthread/pthread_getschedparam.c b/sched/pthread/pthread_getschedparam.c index fa3e030a45..64d4f86063 100644 --- a/sched/pthread/pthread_getschedparam.c +++ b/sched/pthread/pthread_getschedparam.c @@ -104,22 +104,24 @@ int pthread_getschedparam(pthread_t thread, FAR int *policy, /* Get the scheduler parameters of the thread. */ ret = nxsched_getparam((pid_t)thread, param); - if (ret < 0) - { - ret = -ret; - } - - /* Get the scheduler policy. */ - - ret = nxsched_getscheduler((pid_t)thread); if (ret < 0) { ret = -ret; } else { - *policy = ret; - ret = OK; + /* Get the scheduler policy. */ + + ret = nxsched_getscheduler((pid_t)thread); + if (ret < 0) + { + ret = -ret; + } + else + { + *policy = ret; + ret = OK; + } } } diff --git a/sched/pthread/pthread_mutexconsistent.c b/sched/pthread/pthread_mutexconsistent.c index eb37d1fb6d..d4b2b246a9 100644 --- a/sched/pthread/pthread_mutexconsistent.c +++ b/sched/pthread/pthread_mutexconsistent.c @@ -153,10 +153,10 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex) #ifdef CONFIG_PTHREAD_MUTEX_TYPES mutex->nlocks = 0; #endif + ret = OK; } sched_unlock(); - ret = OK; } sinfo("Returning %d\n", ret); diff --git a/sched/sched/sched_setscheduler.c b/sched/sched/sched_setscheduler.c index e2f733cfd6..2147ea8217 100644 --- a/sched/sched/sched_setscheduler.c +++ b/sched/sched/sched_setscheduler.c @@ -141,6 +141,7 @@ int nxsched_setscheduler(pid_t pid, int policy, { default: DEBUGPANIC(); + break; case SCHED_FIFO: { diff --git a/wireless/ieee802154/ieee802154_primitive.c b/wireless/ieee802154/ieee802154_primitive.c index 4b3e14d594..e13c4a3133 100644 --- a/wireless/ieee802154/ieee802154_primitive.c +++ b/wireless/ieee802154/ieee802154_primitive.c @@ -309,12 +309,17 @@ FAR struct ieee802154_primitive_s *ieee802154_primitive_allocate(void) /* Check if we allocated the primitive structure */ - if (prim != NULL) + if (prim == NULL) { - /* Yes... remember that this primitive structure was dynamically allocated */ + /* No.. memory not available */ - pool = POOL_PRIMITIVE_DYNAMIC; + wlerr("ERROR: Failed to allocate primitive.\n"); + return NULL; } + + /* Remember that this primitive structure was dynamically allocated */ + + pool = POOL_PRIMITIVE_DYNAMIC; } }