amdgpu: fix overflow for timeout calculation

Set the timeout to AMDGPU_TIMEOUT_INFINITE when overflow happens

Signed-off-by: Jammy Zhou <Jammy.Zhou@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
main
Jammy Zhou 2015-11-17 17:14:35 +08:00 committed by Alex Deucher
parent 8913cd95b2
commit 9c15b4aacd
1 changed files with 6 additions and 2 deletions

View File

@ -289,12 +289,16 @@ drm_private uint64_t amdgpu_cs_calculate_timeout(uint64_t timeout)
if (timeout != AMDGPU_TIMEOUT_INFINITE) { if (timeout != AMDGPU_TIMEOUT_INFINITE) {
struct timespec current; struct timespec current;
uint64_t current_ns;
r = clock_gettime(CLOCK_MONOTONIC, &current); r = clock_gettime(CLOCK_MONOTONIC, &current);
if (r) if (r)
return r; return r;
timeout += ((uint64_t)current.tv_sec) * 1000000000ull; current_ns = ((uint64_t)current.tv_sec) * 1000000000ull;
timeout += current.tv_nsec; current_ns += current.tv_nsec;
timeout += current_ns;
if (timeout < current_ns)
timeout = AMDGPU_TIMEOUT_INFINITE;
} }
return timeout; return timeout;
} }