From 7b0620501e40435740af2437debd61d8cf9a545e Mon Sep 17 00:00:00 2001 From: Vinod G Date: Tue, 14 May 2019 16:47:22 -0700 Subject: [PATCH] gpu: nvgpu: Fix CERT INT31-C error on common.gr cert_violation: Casting "-1" from "int" to "unsigned int" without checking its value may result in lost or misinterpreted data. Error: CERT INT31-C: Change "(unsigned int)-1" to "~0U" in posix code. Jira NVGPU-3411 Change-Id: I3f1fed7d0788f9ee5c4f2b3c297d7311a0bf2419 Signed-off-by: Vinod G Reviewed-on: https://git-master.nvidia.com/r/2119008 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: Alex Waterman GVS: Gerrit_Virtual_Submit Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/posix/cond.h | 8 ++++++-- drivers/gpu/nvgpu/os/posix/cond.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/cond.h b/drivers/gpu/nvgpu/include/nvgpu/posix/cond.h index 24292e7de..24a4c7092 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/cond.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/cond.h @@ -26,6 +26,8 @@ #include #include +#define NVGPU_COND_WAIT_TIMEOUT_MAX_MS ~0U + struct nvgpu_cond { bool initialized; struct nvgpu_mutex mutex; @@ -54,7 +56,8 @@ void nvgpu_cond_unlock(struct nvgpu_cond *cond); ({ \ int ret = 0; \ NVGPU_COND_WAIT_TIMEOUT_LOCKED(cond, condition, ret, \ - timeout_ms ? timeout_ms : (unsigned int)-1); \ + timeout_ms ? timeout_ms : \ + NVGPU_COND_WAIT_TIMEOUT_MAX_MS); \ ret; \ }) @@ -77,7 +80,8 @@ void nvgpu_cond_unlock(struct nvgpu_cond *cond); NVGPU_COND_WAIT_TIMEOUT_LOCKED((cond), (condition), \ (cond_wait_ret), \ (cond_wait_timeout != 0U) ? \ - (cond_wait_timeout) : (unsigned int)-1); \ + (cond_wait_timeout) : \ + NVGPU_COND_WAIT_TIMEOUT_MAX_MS); \ nvgpu_mutex_release(&(cond)->mutex); \ cond_wait_ret; \ }) diff --git a/drivers/gpu/nvgpu/os/posix/cond.c b/drivers/gpu/nvgpu/os/posix/cond.c index 821cafa27..f1deff14c 100644 --- a/drivers/gpu/nvgpu/os/posix/cond.c +++ b/drivers/gpu/nvgpu/os/posix/cond.c @@ -143,7 +143,7 @@ int nvgpu_cond_timedwait(struct nvgpu_cond *c, unsigned int *ms) s64 t_start_ns, t_ns; struct timespec ts; - if (*ms == (unsigned int)-1) { + if (*ms == NVGPU_COND_WAIT_TIMEOUT_MAX_MS) { return pthread_cond_wait(&c->cond, &c->mutex.lock.mutex); }