This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 35087de0563446b11faf0918eb49637f308e1e16
Author: Szymon Janc <[email protected]>
AuthorDate: Wed Aug 6 11:27:45 2025 +0200

    porting/linux: Fix ble_npl_mutex_pend failing
    
    pthread_mutex_timedlock fails if invalid struct timespec values are
    provided.
---
 porting/npl/linux/src/os_mutex.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/porting/npl/linux/src/os_mutex.c b/porting/npl/linux/src/os_mutex.c
index 86cad965d..3d3a72ef1 100644
--- a/porting/npl/linux/src/os_mutex.c
+++ b/porting/npl/linux/src/os_mutex.c
@@ -71,6 +71,14 @@ ble_npl_mutex_pend(struct ble_npl_mutex *mu, uint32_t 
timeout)
         mu->wait.tv_sec  += timeout / 1000;
         mu->wait.tv_nsec += (timeout % 1000) * 1000000;
 
+        /* struct timespec tv_nsec holds nanosecond and allowed range is
+         * 0 - 999999999, otherwise pthread_mutex_timedlock returns EINVAL
+         */
+        if (mu->wait.tv_nsec >= 1000000000) {
+            mu->wait.tv_sec += mu->wait.tv_nsec / 1000000000;
+            mu->wait.tv_nsec = mu->wait.tv_nsec % 1000000000;
+        }
+
         err = pthread_mutex_timedlock(&mu->lock, &mu->wait);
         if (err == ETIMEDOUT) {
             return BLE_NPL_TIMEOUT;

Reply via email to