summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorPhilip Elcan <pelcan@nvidia.com>2018-09-17 11:39:37 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-09-20 15:58:50 -0400
commit8c4b073537cdde960eaa577c18c46bc075a52b6f (patch)
treec5a5d703cc515987e2d432d7f16c8d41ae362a53 /drivers
parentcec1d923006a9b1a1caabd6a3f415cc6e041defa (diff)
gpu: nvgpu: posix: fix implementation of fls()
The POSIX implementation of fls() wasn't compliant with the Linux which returns fls(0)=0 fls(1)=1, etc. Bug found as result of JIRA NVGPU-1042. Change-Id: Id0279e36332ffe236ed792c013c32f2da841f557 Signed-off-by: Philip Elcan <pelcan@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1828361 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svc-misra-checker <svc-misra-checker@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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/nvgpu/os/posix/bitmap.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/drivers/gpu/nvgpu/os/posix/bitmap.c b/drivers/gpu/nvgpu/os/posix/bitmap.c
index f25f6e64..99ba62c3 100644
--- a/drivers/gpu/nvgpu/os/posix/bitmap.c
+++ b/drivers/gpu/nvgpu/os/posix/bitmap.c
@@ -37,7 +37,18 @@ unsigned long __nvgpu_posix_ffs(unsigned long word)
37 37
38unsigned long __nvgpu_posix_fls(unsigned long word) 38unsigned long __nvgpu_posix_fls(unsigned long word)
39{ 39{
40 return ((sizeof(unsigned long) * 8UL) - 1UL) - __builtin_clzl(word); 40 unsigned long ret;
41
42 if (word == 0UL) {
43 /* __builtin_clzl() below is undefined for 0, so we have
44 * to handle that as a special case.
45 */
46 ret = 0UL;
47 } else {
48 ret = (sizeof(unsigned long) * 8UL) - __builtin_clzl(word);
49 }
50
51 return ret;
41} 52}
42 53
43static unsigned long __find_next_bit(const unsigned long *addr, 54static unsigned long __find_next_bit(const unsigned long *addr,