Libc/pthread: Fix return type of pthread_mutexattr_getprotocol
authorVidisha Thapa <thapa.v@samsung.com>
Fri, 21 Jul 2017 09:30:09 +0000 (15:00 +0530)
committerVidisha Thapa <thapa.v@samsung.com>
Mon, 31 Jul 2017 11:07:25 +0000 (16:37 +0530)
Upon successful completion, pthread_mutexattr_getprotocol() shall return 0;
otherwise, an error number shall be returned to indicate the error.
pthread_mutexattr_getprotocol was returning the protocol rather than 0.

Signed-off-by: Vidisha Thapa <thapa.v@samsung.com>
lib/libc/pthread/pthread_mutexattr_getprotocol.c

index a923fb5..6218ea7 100644 (file)
@@ -59,6 +59,7 @@
 #include <pthread.h>
 #include <assert.h>
 #include <debug.h>
+#include <errno.h>
 
 /****************************************************************************
  * Public Functions
  *
  ****************************************************************************/
 
-int pthread_mutexattr_getprotocol(FAR const pthread_mutexattr_t *attr,
-                                 FAR int *protocol)
+int pthread_mutexattr_getprotocol(FAR const pthread_mutexattr_t *attr, FAR int *protocol)
 {
-       DEBUGASSERT(attr != NULL && protocol != NULL);
-
+       if (attr != NULL && protocol != NULL) {
 #ifdef CONFIG_PRIORITY_INHERITANCE
-       svdbg("Returning %d\n", attr->proto);
-       return attr->proto;
+               svdbg("Returning %d\n", attr->proto);
+               *protocol = attr->proto;
 #else
-       svdbg("Returning %d\n", PTHREAD_PRIO_NONE);
-       return PTHREAD_PRIO_NONE;
+               svdbg("Returning %d\n", PTHREAD_PRIO_NONE);
+               *protocol = PTHREAD_PRIO_NONE;
 #endif
+               return 0;
+       }
+
+       return EINVAL;
 }