Re: [PATCH v3 4/4] x86/CPU/AMD: Print the reason for the last reset

From: Mario Limonciello
Date: Fri Apr 11 2025 - 09:29:29 EST




On 4/11/25 07:50, Borislav Petkov wrote:
On Fri, Apr 11, 2025 at 07:12:24AM -0500, Mario Limonciello wrote:
The idea was to walk all the bits and pick the first one that has a string
associated with it. I was finding that sometimes the reserved bits are set
which would get you a NULL pointer deref.

Uff, that needs a comment at least.

But you can write it a lot simpler instead:

for (i = 0; i <= ARRAY_SIZE(s5_reset_reason_txt); i++) {
if (!(value & BIT(i)))
continue;

if (s5_reset_reason_txt[i])
break;
}

Simple loop, simple statements and all easy. :-)

Right; I was worried about that too but find_next_bit() will return the size
argument when it doesn't find anything.

So that should be s5_reset_reason_txt[32] which has the "Unknown" string.

Yeah, that definitely needs a comment above it.


Thanks; I'll take your simpler solution and leave a comment above the !(value & BIT(i)) check about skipping reserved bits.