From 51dc43de1e3f39c9d117c30bde628266bada200f Mon Sep 17 00:00:00 2001 From: Nitin Kumbhar Date: Thu, 16 May 2019 09:46:16 +0530 Subject: [PATCH] gpu: nvgpu: change return type of __hweight Instead of using unsigned long for all __hweight variants use unsigned int as it's sufficient to hold the result without any data loss. This also matches with return type used in other OS variants like Linux and helps avoid CERT-C errors. Error: CERT INT31-C: drivers/gpu/nvgpu/common/gr/fs_state.c:76: cert_violation: Casting "__hweight32(val)" from "unsigned long" to "unsigned int" without checking its value may result in lost or misinterpreted data. JIRA NVGPU-3410 Change-Id: I7b9167ee21afd04b4ecc05faa838834e1047bf0d Signed-off-by: Nitin Kumbhar Reviewed-on: https://git-master.nvidia.com/r/2119993 GVS: Gerrit_Virtual_Submit Reviewed-by: Deepak Nibade Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/posix/types.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/types.h b/drivers/gpu/nvgpu/include/nvgpu/posix/types.h index 3d5c89f5d..b674787d5 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/types.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/types.h @@ -156,20 +156,20 @@ static inline u32 be32_to_cpu(u32 x) /* * Hamming weights. */ -static inline unsigned long nvgpu_posix_hweight8(uint8_t x) +static inline unsigned int nvgpu_posix_hweight8(uint8_t x) { - unsigned long ret; + unsigned int ret; uint8_t result = x - ((x >> 1) & 0x55U); result = (result & 0x33U) + ((result >> 2) & 0x33U); result = (result + (result >> 4)) & 0x0FU; - ret = (unsigned long)result; + ret = (unsigned int)result; return ret; } -static inline unsigned long nvgpu_posix_hweight16(uint16_t x) +static inline unsigned int nvgpu_posix_hweight16(uint16_t x) { - unsigned long ret; + unsigned int ret; ret = nvgpu_posix_hweight8((uint8_t)x); ret += nvgpu_posix_hweight8((uint8_t)((x & 0xff00U) >> 8)); @@ -177,9 +177,9 @@ static inline unsigned long nvgpu_posix_hweight16(uint16_t x) return ret; } -static inline unsigned long nvgpu_posix_hweight32(uint32_t x) +static inline unsigned int nvgpu_posix_hweight32(uint32_t x) { - unsigned long ret; + unsigned int ret; ret = nvgpu_posix_hweight16((uint16_t)x); ret += nvgpu_posix_hweight16((uint16_t)((x & 0xffff0000U) >> 16)); @@ -187,9 +187,9 @@ static inline unsigned long nvgpu_posix_hweight32(uint32_t x) return ret; } -static inline unsigned long nvgpu_posix_hweight64(uint64_t x) +static inline unsigned int nvgpu_posix_hweight64(uint64_t x) { - unsigned long ret; + unsigned int ret; ret = nvgpu_posix_hweight32((uint32_t)x); ret += nvgpu_posix_hweight32((uint32_t)((x &