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

Xiang W wxjstz at 126.com
Tue Dec 26 17:54:52 PST 2023


在 2023-12-26星期二的 12:03 -0600,Samuel Holland写道:
> On 2023-12-26 9:51 AM, Anup Patel wrote:
> > On Mon, Dec 25, 2023 at 3:19 PM Andreas Schwab <schwab at linux-m68k.org> wrote:
> > > 
> > > 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.
> > 
> > I meant "cur_hartid >= hbase + BITS_PER_LONG" which is
> > the overflow case.
> > 
> > Since the overflow behavior is undefined, we have the
> > explicit check added by this patch.
> 
> As pointed out by Andreas, "cur_hartid - hbase < BITS_PER_LONG" is the only
> check needed here. Unsigned wraparound will take care of the case where
> cur_hartid < hbase.
cur_hartid < hbase is not always true.

For example, cur_hartid is 3 and 0-100 belongs to a domain. Here the loop
is executed twice, the first time with hbase 0 and the second time with
hbase 64. The second loop will have cur_hartid < hbase.

Regards,
Xiang W
> 
> Regards,
> Samuel




More information about the opensbi mailing list