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.  Add safe sub function for
u8 variables to fix the violation.

Jira NVGPU-3609

Change-Id: Ife51f5cc00c7127dd87d5d7b1b3c19ecf7bbfa4d
Signed-off-by: ajesh <akv@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2169974
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
ajesh
2019-08-07 14:26:31 +05:30
committed by mobile promotions
parent 0f19ccb402
commit 6c542f9e34
2 changed files with 14 additions and 3 deletions

View File

@@ -183,10 +183,12 @@ static inline u32 be32_to_cpu(u32 x)
static inline unsigned int nvgpu_posix_hweight8(uint8_t x)
{
unsigned int ret;
uint8_t result = x - ((x >> 1) & 0x55U);
uint8_t result = ((U8(x) >> U8(1)) & U8(0x55));
result = (result & 0x33U) + ((result >> 2) & 0x33U);
result = (result + (result >> 4)) & 0x0FU;
result = nvgpu_safe_sub_u8(x, result);
result = (result & U8(0x33)) + ((result >> U8(2)) & U8(0x33));
result = (result + (result >> U8(4))) & U8(0x0f);
ret = (unsigned int)result;
return ret;