From: Thorsten Blum <thorsten.blum@linux.dev>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>, Ard Biesheuvel <ardb@kernel.org>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest
Date: Fri, 8 May 2026 22:20:59 +0200 [thread overview]
Message-ID: <af5Fq8zWaY9JS5Xf@linux.dev> (raw)
In-Reply-To: <20260508184137.GC4145640@google.com>
On Fri, May 08, 2026 at 06:41:37PM +0000, Eric Biggers wrote:
> On Fri, May 08, 2026 at 04:35:44PM +0200, Thorsten Blum wrote:
> > Change the function's return type from int to bool and return the result
> > of memcmp() directly to simplify the code. While at it, cast ->start to
> > 'const u8 *' to better match the expected type.
> >
> > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> > ---
> > arch/riscv/purgatory/purgatory.c | 9 ++++-----
> > 1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/arch/riscv/purgatory/purgatory.c b/arch/riscv/purgatory/purgatory.c
> > index bbd5cfa4d741..15c72dafa3d8 100644
> > --- a/arch/riscv/purgatory/purgatory.c
> > +++ b/arch/riscv/purgatory/purgatory.c
> > @@ -17,7 +17,7 @@ u8 purgatory_sha256_digest[SHA256_DIGEST_SIZE] __section(".kexec-purgatory");
> >
> > struct kexec_sha_region purgatory_sha_regions[KEXEC_SEGMENT_MAX] __section(".kexec-purgatory");
> >
> > -static int verify_sha256_digest(void)
> > +static bool verify_sha256_digest(void)
> > {
> > struct kexec_sha_region *ptr, *end;
> > struct sha256_ctx sctx;
> > @@ -26,11 +26,10 @@ static int verify_sha256_digest(void)
> > sha256_init(&sctx);
> > end = purgatory_sha_regions + ARRAY_SIZE(purgatory_sha_regions);
> > for (ptr = purgatory_sha_regions; ptr < end; ptr++)
> > - sha256_update(&sctx, (uint8_t *)(ptr->start), ptr->len);
> > + sha256_update(&sctx, (const u8 *)(ptr->start), ptr->len);
> > sha256_final(&sctx, digest);
> > - if (memcmp(digest, purgatory_sha256_digest, sizeof(digest)) != 0)
> > - return 1;
> > - return 0;
> > +
> > + return memcmp(digest, purgatory_sha256_digest, sizeof(digest));
> > }
>
> So true on failure and false on success? Might make sense to flip that.
Ahem yes, that should obviously be flipped. I'll send a v2. Thanks!
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Thorsten Blum <thorsten.blum@linux.dev>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>, Ard Biesheuvel <ardb@kernel.org>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest
Date: Fri, 8 May 2026 22:20:59 +0200 [thread overview]
Message-ID: <af5Fq8zWaY9JS5Xf@linux.dev> (raw)
In-Reply-To: <20260508184137.GC4145640@google.com>
On Fri, May 08, 2026 at 06:41:37PM +0000, Eric Biggers wrote:
> On Fri, May 08, 2026 at 04:35:44PM +0200, Thorsten Blum wrote:
> > Change the function's return type from int to bool and return the result
> > of memcmp() directly to simplify the code. While at it, cast ->start to
> > 'const u8 *' to better match the expected type.
> >
> > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> > ---
> > arch/riscv/purgatory/purgatory.c | 9 ++++-----
> > 1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/arch/riscv/purgatory/purgatory.c b/arch/riscv/purgatory/purgatory.c
> > index bbd5cfa4d741..15c72dafa3d8 100644
> > --- a/arch/riscv/purgatory/purgatory.c
> > +++ b/arch/riscv/purgatory/purgatory.c
> > @@ -17,7 +17,7 @@ u8 purgatory_sha256_digest[SHA256_DIGEST_SIZE] __section(".kexec-purgatory");
> >
> > struct kexec_sha_region purgatory_sha_regions[KEXEC_SEGMENT_MAX] __section(".kexec-purgatory");
> >
> > -static int verify_sha256_digest(void)
> > +static bool verify_sha256_digest(void)
> > {
> > struct kexec_sha_region *ptr, *end;
> > struct sha256_ctx sctx;
> > @@ -26,11 +26,10 @@ static int verify_sha256_digest(void)
> > sha256_init(&sctx);
> > end = purgatory_sha_regions + ARRAY_SIZE(purgatory_sha_regions);
> > for (ptr = purgatory_sha_regions; ptr < end; ptr++)
> > - sha256_update(&sctx, (uint8_t *)(ptr->start), ptr->len);
> > + sha256_update(&sctx, (const u8 *)(ptr->start), ptr->len);
> > sha256_final(&sctx, digest);
> > - if (memcmp(digest, purgatory_sha256_digest, sizeof(digest)) != 0)
> > - return 1;
> > - return 0;
> > +
> > + return memcmp(digest, purgatory_sha256_digest, sizeof(digest));
> > }
>
> So true on failure and false on success? Might make sense to flip that.
Ahem yes, that should obviously be flipped. I'll send a v2. Thanks!
next prev parent reply other threads:[~2026-05-08 20:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 14:35 [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest Thorsten Blum
2026-05-08 14:35 ` Thorsten Blum
2026-05-08 14:35 ` [PATCH RESEND 2/2] riscv/purgatory: add asm/purgatory.h Thorsten Blum
2026-05-08 14:35 ` Thorsten Blum
2026-05-08 18:41 ` [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest Eric Biggers
2026-05-08 18:41 ` Eric Biggers
2026-05-08 20:20 ` Thorsten Blum [this message]
2026-05-08 20:20 ` Thorsten Blum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=af5Fq8zWaY9JS5Xf@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=ardb@kernel.org \
--cc=ebiggers@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.