[PATCH] lib: sbi: Fix shift bug in sbi_system_reset

Xiang W wxjstz at 126.com
Mon Dec 25 08:09:42 PST 2023


在 2023-12-25星期一的 10:48 +0100,Andreas Schwab写道:
> On Dez 25 2023, Anup Patel wrote:
> 
> > If "cur_hartid < hbase + BITS_PER_LONG" then
> > "1UL << (cur_hartid - hbase) == 0x0"
> 
> If cur_hartid - hbase < BITS_PER_LONG, then 1UL << (cur_hartid - hbase)
> will not be 0.  If cur_hartid - hbase >= BITS_PER_LONG, then 1UL <<
> (cur_hartid - hbase) will overflow and be undefined.
> 
Andreas is right. C99 semantics require that the result of a shift overflow
is undefined. Under RISCV, 1<< n is equal to 1<<(n%XLAN).

Regards,
Xiang W




More information about the opensbi mailing list