[PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest

Eric Biggers ebiggers at kernel.org
Fri May 8 11:41:37 PDT 2026


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 at 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.

- Eric



More information about the linux-riscv mailing list