]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
riscv/purgatory: return bool from verify_sha256_digest
authorThorsten Blum <thorsten.blum@linux.dev>
Sun, 7 Jun 2026 02:17:51 +0000 (20:17 -0600)
committerPaul Walmsley <pjw@kernel.org>
Sun, 7 Jun 2026 02:17:51 +0000 (20:17 -0600)
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>
Link: https://patch.msgid.link/20260509073850.44595-3-thorsten.blum@linux.dev
Signed-off-by: Paul Walmsley <pjw@kernel.org>
arch/riscv/purgatory/purgatory.c

index bbd5cfa4d7412f65d55a8cf2dc604210cdd149ba..745deeb6e3a5f9fcb7d0382970be73a28abd91a2 100644 (file)
@@ -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)) == 0;
 }
 
 /* workaround for a warning with -Wmissing-prototypes */
@@ -38,7 +37,7 @@ void purgatory(void);
 
 void purgatory(void)
 {
-       if (verify_sha256_digest())
+       if (!verify_sha256_digest())
                for (;;)
                        /* loop forever */
                        ;