[rtems commit] rtems: Improve semaphore create error checks

Sebastian Huber sebh at rtems.org
Wed Mar 17 09:46:58 UTC 2021


Module:    rtems
Branch:    master
Commit:    b4eb937ecdd9505b59f038a7f97ae76ae25c3182
Changeset: http://git.rtems.org/rtems/commit/?id=b4eb937ecdd9505b59f038a7f97ae76ae25c3182

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Mar 12 15:13:27 2021 +0100

rtems: Improve semaphore create error checks

Do not mix checks for different error indicators (RTEMS_NOT_DEFINED and
RTEMS_INVALID_NUMBER).  This simplifies the specification of
rtems_semaphore_create().

---

 cpukit/rtems/src/semcreate.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c
index 0246c91..b58ea01 100644
--- a/cpukit/rtems/src/semcreate.c
+++ b/cpukit/rtems/src/semcreate.c
@@ -72,12 +72,6 @@ rtems_status_code rtems_semaphore_create(
 
   if ( maybe_global == RTEMS_COUNTING_SEMAPHORE ) {
     variant = SEMAPHORE_VARIANT_COUNTING;
-  } else if ( count > 1 ) {
-    /*
-     * The remaining variants are all binary semphores, thus reject an invalid
-     * count value.
-     */
-    return RTEMS_INVALID_NUMBER;
   } else if ( maybe_global == RTEMS_SIMPLE_BINARY_SEMAPHORE ) {
     variant = SEMAPHORE_VARIANT_SIMPLE_BINARY;
   } else if ( maybe_global == RTEMS_BINARY_SEMAPHORE ) {
@@ -109,6 +103,10 @@ rtems_status_code rtems_semaphore_create(
     return RTEMS_NOT_DEFINED;
   }
 
+  if ( count > 1 && variant != SEMAPHORE_VARIANT_COUNTING ) {
+    return RTEMS_INVALID_NUMBER;
+  }
+
   the_semaphore = _Semaphore_Allocate();
 
   if ( !the_semaphore ) {



More information about the vc mailing list