From 891113dac93d1fccfb53851e92ee46cc030e9cd3 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Tue, 28 Jun 2016 10:06:30 -0400 Subject: [PATCH] sched/semaphore: Fix setting EINVAL in sem_post() and sem_wait() --- sched/semaphore/sem_post.c | 5 +++++ sched/semaphore/sem_wait.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/sched/semaphore/sem_post.c b/sched/semaphore/sem_post.c index 97235de428..c985ceb9c4 100644 --- a/sched/semaphore/sem_post.c +++ b/sched/semaphore/sem_post.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -157,6 +158,10 @@ int sem_post(FAR sem_t *sem) leave_critical_section(flags); } + else + { + set_errno(EINVAL); + } return ret; } diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c index 86fb013696..49371e0ae6 100644 --- a/sched/semaphore/sem_wait.c +++ b/sched/semaphore/sem_wait.c @@ -86,9 +86,7 @@ int sem_wait(FAR sem_t *sem) DEBUGASSERT(up_interrupt_context() == false); - /* Assume any errors reported are due to invalid arguments. */ - - set_errno(EINVAL); + /* Make sure we were supplied with a valid semaphore. */ if (sem) { @@ -190,6 +188,10 @@ int sem_wait(FAR sem_t *sem) leave_critical_section(flags); } + else + { + set_errno(EINVAL); + } return ret; }