From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75B4C3DA5A5 for ; Fri, 8 May 2026 18:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778265699; cv=none; b=IYyuAHqrfkvMsCZZQh0g9czkHLQnRek4WJtlRena7IR9C2ZDn6tNvhwyFJ98U14rv2Ytbz4smk4//ErMP3g+bNacjvfyDXThTcwZevDRzUsveRmk6RjSy1crRAurJ3jILS3sWmMNbTg+PbM1B0z+FfBE26blePUf1UCS1xy18/Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778265699; c=relaxed/simple; bh=zWGYuuD6D0rII7IevVsdnkUt1rJLodo8g4uWZrT0jV0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eab+21mf0FrAw1TUA8YkoAD5UmknkfEVXtMNLtFTKDJixhQDvfCBk5DE0IkdmTTD4S6JySD1F9ssa/2JcQS+vzSO7+SuiZlX+tG8xR0kP2tftkc3ecW4EmCgBA5UsJ291LSwoDgJQaxD5TyvNLWbQSpsqCnRdDQHuqdd9R1TOuM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tpBJwe88; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tpBJwe88" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12AE5C2BCB0; Fri, 8 May 2026 18:41:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778265699; bh=zWGYuuD6D0rII7IevVsdnkUt1rJLodo8g4uWZrT0jV0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tpBJwe88fKjZkP3TU9zS/pKJE+T6DTkIh2ftBlF+z6BtzVZQDmvLU4LkZmt5umZgH A0tAUXYcMx67xGUnIsUMHLJYK2Bi6MyW+IJzMtSVsC85OiCfjq5K6Q89LzxqIYU8Fg wX96cKIJYj+ATwzrGP5qpcXptoei/QoccVaarQHdpG8b5k/JpWW3E+qN48nM1jcTTK q/cPGyoAx4RPkpX6soj+1hLbU/adHhWEGfu4kn93CSIM/qwA3jTTYdVxXPCL9nbidJ AnyYYN76kdDqi6rs1C3sLNtgaYNHUUdcQn3hcwrIlrHMku4yTBX3NjbT24ihcTIiHo GeOW3Uj8IoUKQ== Date: Fri, 8 May 2026 18:41:37 +0000 From: Eric Biggers To: Thorsten Blum Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Ard Biesheuvel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest Message-ID: <20260508184137.GC4145640@google.com> References: <20260508143544.2484-3-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260508143544.2484-3-thorsten.blum@linux.dev> 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 > --- > 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