From: Thorsten Blum <thorsten.blum@linux.dev>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>, linux-kernel@vger.kernel.org
Subject: [PATCH] x86/purgatory: Return bool from verify_sha256_digest()
Date: Wed, 22 Jul 2026 18:22:45 +0200 [thread overview]
Message-ID: <20260722162245.156368-2-thorsten.blum@linux.dev> (raw)
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.
Also inline the verify_sha256_digest() check and remove the redundant
local ret variable in purgatory().
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/x86/purgatory/purgatory.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/arch/x86/purgatory/purgatory.c b/arch/x86/purgatory/purgatory.c
index 655139dd0532..3ea8eb6af11f 100644
--- a/arch/x86/purgatory/purgatory.c
+++ b/arch/x86/purgatory/purgatory.c
@@ -21,7 +21,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;
u8 digest[SHA256_DIGEST_SIZE];
@@ -31,22 +31,16 @@ static int verify_sha256_digest(void)
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)))
- return 1;
-
- return 0;
+ return memcmp(digest, purgatory_sha256_digest, sizeof(digest)) == 0;
}
void purgatory(void)
{
- int ret;
-
- ret = verify_sha256_digest();
- if (ret) {
+ if (!verify_sha256_digest()) {
/* loop forever */
for (;;)
;
reply other threads:[~2026-07-22 16:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260722162245.156368-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@kernel.org \
--cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox