Fix various issues noted by Coverity

This commit is contained in:
Alan Carvalho de Assis 2018-02-06 09:13:16 -06:00 committed by Gregory Nutt
parent 56bb76caca
commit fb50c44d08
8 changed files with 34 additions and 19 deletions

View File

@ -77,7 +77,7 @@
int nxsem_getvalue(FAR sem_t *sem, FAR int *sval) int nxsem_getvalue(FAR sem_t *sem, FAR int *sval)
{ {
if (sem && sval) if (sem != NULL && sval != NULL)
{ {
*sval = sem->semcount; *sval = sem->semcount;
return OK; return OK;

View File

@ -1174,7 +1174,7 @@ int psock_tcp_cansend(FAR struct socket *psock)
return -ENOTCONN; return -ENOTCONN;
} }
if (tcp_wrbuffer_test()) if (tcp_wrbuffer_test() < 0)
{ {
return -EWOULDBLOCK; return -EWOULDBLOCK;
} }

View File

@ -211,8 +211,15 @@ void tcp_wrbuffer_release(FAR struct tcp_wrbuffer_s *wrb)
int tcp_wrbuffer_test(void) int tcp_wrbuffer_test(void)
{ {
int val = 0; int val = 0;
nxsem_getvalue(&g_wrbuffer.sem, &val); int ret;
return val > 0 ? OK : ERROR;
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 */ #endif /* CONFIG_NET && CONFIG_NET_TCP && CONFIG_NET_TCP_WRITE_BUFFERS */

View File

@ -302,7 +302,7 @@ ssize_t nxmq_do_receive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg,
* time the task is unblocked * time the task is unblocked
*/ */
DEBUGASSERT(btcb); DEBUGASSERT(btcb != NULL);
btcb->msgwaitq = NULL; btcb->msgwaitq = NULL;
msgq->nwaitnotfull--; msgq->nwaitnotfull--;

View File

@ -104,22 +104,24 @@ int pthread_getschedparam(pthread_t thread, FAR int *policy,
/* Get the scheduler parameters of the thread. */ /* Get the scheduler parameters of the thread. */
ret = nxsched_getparam((pid_t)thread, param); 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) if (ret < 0)
{ {
ret = -ret; ret = -ret;
} }
else else
{ {
*policy = ret; /* Get the scheduler policy. */
ret = OK;
ret = nxsched_getscheduler((pid_t)thread);
if (ret < 0)
{
ret = -ret;
}
else
{
*policy = ret;
ret = OK;
}
} }
} }

View File

@ -153,10 +153,10 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex)
#ifdef CONFIG_PTHREAD_MUTEX_TYPES #ifdef CONFIG_PTHREAD_MUTEX_TYPES
mutex->nlocks = 0; mutex->nlocks = 0;
#endif #endif
ret = OK;
} }
sched_unlock(); sched_unlock();
ret = OK;
} }
sinfo("Returning %d\n", ret); sinfo("Returning %d\n", ret);

View File

@ -141,6 +141,7 @@ int nxsched_setscheduler(pid_t pid, int policy,
{ {
default: default:
DEBUGPANIC(); DEBUGPANIC();
break;
case SCHED_FIFO: case SCHED_FIFO:
{ {

View File

@ -309,12 +309,17 @@ FAR struct ieee802154_primitive_s *ieee802154_primitive_allocate(void)
/* Check if we allocated the primitive structure */ /* 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;
} }
} }