From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 AB9692F90C9 for ; Sun, 12 Apr 2026 19:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776022943; cv=none; b=L5JjSAKkDzRcYFSCguO2JZWTsH0erPAcQlqae8TNAH8AoZkF2X4Jf4+Uucq134mNYyr3hAyLQz7ajIRf20B9wcse9v5t71nBBIIxAh4tRwsFjGfvQhfawTPngpzvCm7NuUl+GYsqsATEFX/JPyz2m8kkYzX24ni5kFUFXiGMV4I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776022943; c=relaxed/simple; bh=zV4hfU38HPXgefG3ua5/+P1VbvLku9DJirIeEEEnM8s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cFzkj7mEcd0+yr0cOjwQcYTTIaEBdbpmcVC+7UaZce5xksZaeR4Z+0gAi8ScfoXrKgHOkigdOOTAieMk2ghD/1LUOk8D6N/Dnd34WsFJGcn+GrmXeaHenRmV042kJ/KwY3NDmkPVLjyPciim7DsXSdHgSa026EZFxsKlm1sGexc= 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=aTLqxri8; arc=none smtp.client-ip=91.218.175.180 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="aTLqxri8" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776022939; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=IvoGuPSpwla1RHAl1U8V7E6i8CVr6Fu/69QlhrzLoA4=; b=aTLqxri8lSyTkL9a1bis7NmvFerHKBfwmPv+MvwaELjyNuNoSaGGvDkUpnPnwBmiG9L1sL YYmfBlL6EANeshD0hmZJRnCvz1/yib6ZPMHWfMf5pAOMYdKRKUO704idsKS0kXPBGBbWbr f1qcz+cNRnFdbkzUdcb4a6u/6Wav0YY= From: Thorsten Blum To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Eric Biggers , Ard Biesheuvel Cc: Thorsten Blum , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] riscv/purgatory: return bool from verify_sha256_digest Date: Sun, 12 Apr 2026 21:41:14 +0200 Message-ID: <20260412194113.228703-4-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1508; i=thorsten.blum@linux.dev; h=from:subject; bh=zV4hfU38HPXgefG3ua5/+P1VbvLku9DJirIeEEEnM8s=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDJm3v0aeOXm2dXvY/bZN15dpRd2Quf7OrjNln9m0Bdenr vc7U9bK0FHKwiDGxSArpsjyYNaPGb6lNZWbTCJ2wsxhZQIZwsDFKQATcXzP8E9zoZLx3ILHcdde Njsc7mzMCzZ05X6RoP0tJeACj2CAbRAjQ8u+n1sWdAkfvhEQNzu8jv1Z1bVdrhWqW2b83uaVUPB nHR8A X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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)); } /* workaround for a warning with -Wmissing-prototypes */