gpu: nvgpu: add safe typecast operations

Add function to typecast s8 to u8 in safe way. This function throws
an error if operand is more than CHAR_MAX.

JIRA NVGPU-3432
JIRA NVGPU-3438

Change-Id: Ieb712e6bcf187d6f26aaa1f2e0d8e6d2a17bcc54
Signed-off-by: Vaibhav Kachore <vkachore@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2124258
Reviewed-by: Deepak Nibade <dnibade@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Vaibhav Kachore
2019-05-23 17:27:00 +05:30
committed by mobile promotions
parent f4a040cc9d
commit bfd7b0e386

View File

@@ -95,4 +95,21 @@ static inline u32 nvgpu_safe_cast_bool_to_u32(bool bl_a)
return bl_a == true ? 1U : 0U;
}
static inline u8 nvgpu_safe_cast_s8_to_u8(s8 sc_a)
{
if (sc_a < 0) {
BUG();
} else {
return (u8)sc_a;
}
}
static inline u32 nvgpu_safe_cast_s32_to_u32(s32 si_a)
{
if (si_a < 0) {
BUG();
} else {
return (u32)si_a;
}
}
#endif /* NVGPU_SAFE_OPS_H */