From a5d8f4f9752f4cb1a1e9cc728a0e90477e508a03 Mon Sep 17 00:00:00 2001 From: Echo J Date: Thu, 1 Aug 2024 20:42:36 +0300 Subject: [PATCH] util: Fix the integer addition in os_time_get_absolute_timeout() This should fix glClientWaitSync() timing out too early with a INT64_MAX timeout on radeonsi Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11615 Fixes: 7316cc92f38 ("gallium/os: add conversion and wait functions for absolute timeouts") Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: (cherry picked from commit e14d1f5bc0a0579e8a9934c96a6ca22646da06ac) --- .pick_status.json | 2 +- src/util/os_time.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 20246491748..8479c4cf278 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -4994,7 +4994,7 @@ "description": "util: Fix the integer addition in os_time_get_absolute_timeout()", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "7316cc92f3810c9e53a22c35343190d8fb7980be", "notes": null diff --git a/src/util/os_time.c b/src/util/os_time.c index 37548a8544b..40949abb6eb 100644 --- a/src/util/os_time.c +++ b/src/util/os_time.c @@ -97,7 +97,9 @@ os_time_get_absolute_timeout(uint64_t timeout) return OS_TIMEOUT_INFINITE; time = os_time_get_nano(); - abs_timeout = time + (int64_t)timeout; + + /* Do the addition in unsigned, because signed overflow is UB, then convert to signed again. */ + abs_timeout = (uint64_t)time + (uint64_t)timeout; /* Check for overflow. */ if (abs_timeout < time)