mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-23 18:16:01 +03:00
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 <nkumbhar@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/2119993 GVS: Gerrit_Virtual_Submit Reviewed-by: Deepak Nibade <dnibade@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
709896c48d
commit
51dc43de1e
@@ -156,20 +156,20 @@ static inline u32 be32_to_cpu(u32 x)
|
|||||||
/*
|
/*
|
||||||
* Hamming weights.
|
* 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);
|
uint8_t result = x - ((x >> 1) & 0x55U);
|
||||||
|
|
||||||
result = (result & 0x33U) + ((result >> 2) & 0x33U);
|
result = (result & 0x33U) + ((result >> 2) & 0x33U);
|
||||||
result = (result + (result >> 4)) & 0x0FU;
|
result = (result + (result >> 4)) & 0x0FU;
|
||||||
ret = (unsigned long)result;
|
ret = (unsigned int)result;
|
||||||
|
|
||||||
return ret;
|
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);
|
||||||
ret += nvgpu_posix_hweight8((uint8_t)((x & 0xff00U) >> 8));
|
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;
|
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);
|
||||||
ret += nvgpu_posix_hweight16((uint16_t)((x & 0xffff0000U) >> 16));
|
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;
|
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);
|
||||||
ret += nvgpu_posix_hweight32((uint32_t)((x &
|
ret += nvgpu_posix_hweight32((uint32_t)((x &
|
||||||
|
|||||||
Reference in New Issue
Block a user