From 9aaeaefa415a919d3228f5bb520c71dd412a1858 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Jun 2021 15:12:15 -0600 Subject: [PATCH] TLS: Correct handling of returned error values. I not two problems in handling of the return error values in PR #3858: 1. In KERNEL mode, the error return value of _SEM_WAIT() will be a negated errno value; in all other modes, it will be -1 (ERROR) with the errno variable set. This must be handled in the test of the returned value: Don't compare with -1; rather check if < 0 2. Also, conversion of the returned value to a negated errno value must be handled differently. This is handled by replacing -get_errno() with the macro _ERRVAL(ret) This effects only error handling (it fixes it) and no other impacts are expected. --- libs/libc/tls/tls_alloc.c | 5 ++--- libs/libc/tls/tls_free.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/libc/tls/tls_alloc.c b/libs/libc/tls/tls_alloc.c index 2630e7e415b..ea170a16cc0 100644 --- a/libs/libc/tls/tls_alloc.c +++ b/libs/libc/tls/tls_alloc.c @@ -66,10 +66,9 @@ int tls_alloc(void) */ ret = _SEM_WAIT(&tinfo->ta_tlssem); - - if (ERROR == ret) + if (ret < 0) { - ret = -get_errno(); + ret = _SEM_ERRVAL(ret); goto errout_with_errno; } diff --git a/libs/libc/tls/tls_free.c b/libs/libc/tls/tls_free.c index 7455e08cb33..9cbe4a42387 100644 --- a/libs/libc/tls/tls_free.c +++ b/libs/libc/tls/tls_free.c @@ -79,7 +79,7 @@ int tls_free(int tlsindex) } else { - ret = -get_errno(); + ret = _SEM_ERRVAL(ret); } }