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

Samuel Holland samuel.holland at sifive.com
Tue Dec 26 10:03:58 PST 2023


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.

Regards,
Samuel




More information about the opensbi mailing list