All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86/purgatory: Return bool from verify_sha256_digest()
@ 2026-07-23 13:36 Thorsten Blum
  2026-07-23 14:03 ` [tip: x86/boot] " tip-bot2 for Thorsten Blum
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-07-23 13:36 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin
  Cc: Thorsten Blum, linux-kernel

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>
---
Changes in v2:
- Return !memcmp() as suggested by Ingo
- v1: https://lore.kernel.org/r/20260722162245.156368-2-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..45836aca1a4b 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));
 }
 
 void purgatory(void)
 {
-	int ret;
-
-	ret = verify_sha256_digest();
-	if (ret) {
+	if (!verify_sha256_digest()) {
 		/* loop forever */
 		for (;;)
 			;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [tip: x86/boot] x86/purgatory: Return bool from verify_sha256_digest()
  2026-07-23 13:36 [PATCH v2] x86/purgatory: Return bool from verify_sha256_digest() Thorsten Blum
@ 2026-07-23 14:03 ` tip-bot2 for Thorsten Blum
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Thorsten Blum @ 2026-07-23 14:03 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Thorsten Blum, Ingo Molnar, H. Peter Anvin, x86, linux-kernel

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     10a357ce443dad3ec985506485c6b37d34c382f2
Gitweb:        https://git.kernel.org/tip/10a357ce443dad3ec985506485c6b37d34c382f2
Author:        Thorsten Blum <thorsten.blum@linux.dev>
AuthorDate:    Thu, 23 Jul 2026 15:36:34 +02:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 23 Jul 2026 15:45:02 +02:00

x86/purgatory: Return bool from verify_sha256_digest()

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().

No change in functionality expected.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Link: https://patch.msgid.link/20260723133634.161598-3-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 655139d..45836ac 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));
 }
 
 void purgatory(void)
 {
-	int ret;
-
-	ret = verify_sha256_digest();
-	if (ret) {
+	if (!verify_sha256_digest()) {
 		/* loop forever */
 		for (;;)
 			;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-23 14:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 13:36 [PATCH v2] x86/purgatory: Return bool from verify_sha256_digest() Thorsten Blum
2026-07-23 14:03 ` [tip: x86/boot] " tip-bot2 for Thorsten Blum

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.