summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorXiang W <wxjstz@126.com>2021-09-15 09:50:52 +0300
committerAnup Patel <anup@brainfault.org>2021-09-22 10:56:23 +0300
commit3477f08b08da6bfd904218fdb76b3db592dd7ebd (patch)
tree2b2d0fe0b50f5ca8a4763fb88b434dcfd52d7c5e /lib
parent395ff7eedec5e2b5b067e3725303a17352a07651 (diff)
downloadopensbi-3477f08b08da6bfd904218fdb76b3db592dd7ebd.tar.xz
lib: sbi: fix ctz bug
The original version of ctz will cause an endless loop, if the parameter passed in is 0. This commit fixes this bug. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi/riscv_asm.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c
index 4c24a51..d7b9b2b 100644
--- a/lib/sbi/riscv_asm.c
+++ b/lib/sbi/riscv_asm.c
@@ -213,6 +213,9 @@ static unsigned long ctz(unsigned long x)
{
unsigned long ret = 0;
+ if (x == 0)
+ return 8 * sizeof(x);
+
while (!(x & 1UL)) {
ret++;
x = x >> 1;