From e7ce9c4a7958b32457aee4eab7b26c6a439639c3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 8 Sep 2017 10:14:51 -0600 Subject: [PATCH] sem_open() should return SEM_FAILED on any failures. This is change change in the POSIX specification since the original sem_open() was written so many years ago. --- Documentation/NuttxUserGuide.html | 2 +- drivers/wireless/cc3000/cc3000drv.c | 2 +- fs/semaphore/sem_open.c | 4 ++-- include/semaphore.h | 4 ++++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Documentation/NuttxUserGuide.html b/Documentation/NuttxUserGuide.html index 0a8233775cd..47cb387d300 100644 --- a/Documentation/NuttxUserGuide.html +++ b/Documentation/NuttxUserGuide.html @@ -3697,7 +3697,7 @@ semaphores must be less than or equal to SEM_VALUE_MAX (defined in

Returned Value:

diff --git a/drivers/wireless/cc3000/cc3000drv.c b/drivers/wireless/cc3000/cc3000drv.c index ab114c0515a..6327371a474 100644 --- a/drivers/wireless/cc3000/cc3000drv.c +++ b/drivers/wireless/cc3000/cc3000drv.c @@ -192,7 +192,7 @@ static void *unsoliced_thread_func(void *parameter) DEBUGASSERT(SEM_NAMELEN == QUEUE_NAMELEN); snprintf(buff, SEM_NAMELEN, SEM_FORMAT, minor); spiconf.done = sem_open(buff, O_RDONLY); - DEBUGASSERT(spiconf.done != (sem_t *)-1); + DEBUGASSERT(spiconf.done != SEM_FAILED); sem_post(&spiconf.unsoliced_thread_wakesem); diff --git a/fs/semaphore/sem_open.c b/fs/semaphore/sem_open.c index aad94091b1d..4055b66ba79 100644 --- a/fs/semaphore/sem_open.c +++ b/fs/semaphore/sem_open.c @@ -94,7 +94,7 @@ * SEM_VALUE_MAX. * * Return Value: - * A pointer to sem_t or -1 (ERROR) if unsuccessful. + * A pointer to sem_t or SEM_FAILED if unsuccessful. * * Assumptions: * @@ -257,7 +257,7 @@ errout_with_lock: RELEASE_SEARCH(&desc); set_errno(errcode); sched_unlock(); - return (FAR sem_t *)ERROR; + return SEM_FAILED; } #endif /* CONFIG_FS_NAMED_SEMAPHORES */ diff --git a/include/semaphore.h b/include/semaphore.h index e14b1aa409e..9a87461edf0 100644 --- a/include/semaphore.h +++ b/include/semaphore.h @@ -49,6 +49,10 @@ * Pre-processor Definitions ****************************************************************************/ +/* Value returned by sem_open() in the event of a failure. */ + +#define SEM_FAILED ((FAR sem_t *)NULL) + /* Bit definitions for the struct sem_s flags field */ #define PRIOINHERIT_FLAGS_DISABLE (1 << 0) /* Bit 0: Priority inheritance