mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
gpu: nvgpu: posix: make round*_pow_of_two CERT-C friendly
CERT-C Rule INT30 requires checking unsigned arithmetic for potential wrap. The macros roundup_pow_of_two and rounddown_pow_of_two could potentially wrap if the passed parameter were 0. JIRA NVGPU-3586 Change-Id: I9eba4c197b74db555055e1199ce72131b071062c Signed-off-by: Philip Elcan <pelcan@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/2131157 GVS: Gerrit_Virtual_Submit Reviewed-by: Nitin Kumbhar <nkumbhar@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
7eb8ea9764
commit
be7c7aa040
@@ -33,8 +33,29 @@
|
||||
fls_val; \
|
||||
})
|
||||
|
||||
#define roundup_pow_of_two(x) (1UL << fls((x) - 1UL))
|
||||
#define rounddown_pow_of_two(x) (1UL << (fls(x) - 1UL))
|
||||
#define roundup_pow_of_two(x) \
|
||||
({ \
|
||||
unsigned long ret; \
|
||||
\
|
||||
if ((x) == 0UL) { \
|
||||
BUG(); \
|
||||
} else { \
|
||||
ret = 1UL << fls((x) - 1UL); \
|
||||
} \
|
||||
ret; \
|
||||
})
|
||||
|
||||
#define rounddown_pow_of_two(x) \
|
||||
({ \
|
||||
unsigned long ret; \
|
||||
\
|
||||
if ((x) == 0UL) { \
|
||||
BUG(); \
|
||||
} else { \
|
||||
ret = 1UL << (fls(x) - 1UL); \
|
||||
} \
|
||||
ret; \
|
||||
})
|
||||
|
||||
#define is_power_of_2(x) \
|
||||
(bool)({ \
|
||||
|
||||
Reference in New Issue
Block a user