From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 4BC303E0C68 for ; Fri, 8 May 2026 20:21:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778271667; cv=none; b=qt6WtLVvRVBdDiycQSP/60AMrvdmk31wH+vz4suCcAxqdd+1Xk0483UO4CLabarK4xnCxaM7gOZcmlsBgdaBdyCQJKgDI2+4rxUOZ4Vm7HZsichezKdCJV9I/CA9kJU6nGd/iUxsmEuxlMKProlb72dOD12g+M/ww4xxPSIeOxw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778271667; c=relaxed/simple; bh=dHKJ8k1m9jmQQN6EXS/mWvqR7OaAWQJhI8efs/mSjLE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XKojxHE8BeoWc0Jm5JnfIQWiVOmpIdW8x2d0QB7tIQqDx/3xhw3EWQ3ormfvY84P3W3i+ar7XQIVlOUNLKIwb07vzA/zxE8zrzwXdSVWYlxqXpG68RpG9IDOGmFvqh5t+qT7gWir3b8kg1rdPF58YQD4OgsLqzE+No8wH5HJhpQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=sMBLF0/i; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="sMBLF0/i" Date: Fri, 8 May 2026 22:20:59 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778271663; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=9mS8gtYntpLCSU0tApfkVV6AUA34BBbgret+6ejxc+k=; b=sMBLF0/izGlHqk5z4o3Ierxy+U4DQT1NcRMe4qklRhvUjZm7S065MhPD++t/EzsacxtJco xCyd9E2P3qboH39E5+9kSUsMF7oo9V3oRF15pfHsNM+Yioblr48CoLISlpO9CUjAMhBe1F STFPyQ1pkGFEfEcZakQbp1J8CrqZU74= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Thorsten Blum To: Eric Biggers 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: References: <20260508143544.2484-3-thorsten.blum@linux.dev> <20260508184137.GC4145640@google.com> 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: <20260508184137.GC4145640@google.com> X-Migadu-Flow: FLOW_OUT On Fri, May 08, 2026 at 06:41:37PM +0000, Eric Biggers wrote: > 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. Ahem yes, that should obviously be flipped. I'll send a v2. Thanks!