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 <vinodg@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2119008
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-misra <svc-mobile-misra@nvidia.com>
Reviewed-by: Alex Waterman <alexw@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Vinod G
2019-05-14 16:47:22 -07:00
committed by mobile promotions
parent fb89f656d7
commit 7b0620501e
2 changed files with 7 additions and 3 deletions

View File

@@ -26,6 +26,8 @@
#include <nvgpu/bug.h>
#include <nvgpu/lock.h>
#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; \
})

View File

@@ -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);
}