[PATCH] lib: sbi: fix ctz bug
Anup Patel
anup at brainfault.org
Wed Sep 22 00:56:11 PDT 2021
On Wed, Sep 15, 2021 at 1:02 PM Bin Meng <bmeng.cn at gmail.com> wrote:
>
> On Wed, Sep 15, 2021 at 2:51 PM Xiang W <wxjstz at 126.com> wrote:
> >
> > 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 at 126.com>
> > ---
> > lib/sbi/riscv_asm.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > 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;
>
> Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
Looks good to me.
Reviewed-by: Anup Patel <anup.patel at wdc.com>
Regards,
Anup
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
More information about the opensbi
mailing list