mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 15:31:22 +01:00
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>
This commit is contained in:
@@ -213,6 +213,9 @@ static unsigned long ctz(unsigned long x)
|
|||||||
{
|
{
|
||||||
unsigned long ret = 0;
|
unsigned long ret = 0;
|
||||||
|
|
||||||
|
if (x == 0)
|
||||||
|
return 8 * sizeof(x);
|
||||||
|
|
||||||
while (!(x & 1UL)) {
|
while (!(x & 1UL)) {
|
||||||
ret++;
|
ret++;
|
||||||
x = x >> 1;
|
x = x >> 1;
|
||||||
|
Reference in New Issue
Block a user