From 0f19ccb4027036d65c78581e9be2ccb0bb75bb2f Mon Sep 17 00:00:00 2001 From: ajesh Date: Wed, 7 Aug 2019 11:41:19 +0530 Subject: [PATCH] gpu: nvgpu: fix certc violations in utils unit INT31-C Requires that integer conversions do not result in lost or misinterpreted data. Fix violations of INT31-C in utils unit. Jira NVGPU-3609 Change-Id: I6d216fc76b2c84f81a0fc0f67822e6bc632b8397 Signed-off-by: ajesh Reviewed-on: https://git-master.nvidia.com/r/2169861 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Philip Elcan Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/posix/utils.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h b/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h index 42f0badbc..f2db92d6d 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h @@ -214,10 +214,13 @@ static inline unsigned int nvgpu_posix_hweight32(uint32_t x) static inline unsigned int nvgpu_posix_hweight64(uint64_t x) { unsigned int ret; + u32 lo, hi; - ret = nvgpu_posix_hweight32((uint32_t)x); - ret += nvgpu_posix_hweight32((uint32_t)((x & - 0xffffffff00000000U) >> 32)); + lo = nvgpu_safe_cast_u64_to_u32(x & ~(u32)0); + hi = nvgpu_safe_cast_u64_to_u32(x >> 32) & ~(u32)0; + + ret = nvgpu_posix_hweight32(lo); + ret += nvgpu_posix_hweight32(hi); return ret; }