From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 D8676439F99 for ; Wed, 22 Jul 2026 16:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784737394; cv=none; b=fO8qpzZ70pjmqJ0WBKSMllhLz9jvWp7zm4Ie1/2m04O640fsEwnLocXJ36/WfbgUYuxaxB3MoPC/cP3082Edtbq7bmTaT3DY8AHj0o29LKD3Bom1Fiw+FYrL+AGmghfTnyNCJ7UIYppObDg3euPstu2EaZbG5/tZM+Nd6PrQtSI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784737394; c=relaxed/simple; bh=tBSocjZ0nsTDh/xrtReDm7hd/b4f+tgP/DNjMcBGXTs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=l/Iy8MfNOkfctYgXE51e8dcvTwaF5cc6CObrsaOt1ogQ6YWRGHnAbyobfM0PND1LGtIw7pZ4pC7Zbg3ER/fuvpYAr282v1WdWf6OjxL8TwddOP8Gr8abP00+iSQ92JAj8NGezhhj+LXFC8fDUvqiJ4dsD5QDHE4zfV8l3LmqFOQ= 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=wZzF2F4I; arc=none smtp.client-ip=91.218.175.171 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="wZzF2F4I" 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=1784737389; 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=8RWG9ST0HBqgJ6nvMiiBosBueUgd1PNRsG4HKKn1l4Y=; b=wZzF2F4IRG7eam57mlc56Mc+vJJRIH+Bmp/tRAZXhE7EZh2DhLO38Tds5JRU0Q0rbMuLKd BXA1CNOitJHl/VPBQGak+vQpCcWa/sAMnyTKAi745W5d4MV3ONan/G7DulzzWC1Qwvh3X0 5BmjSbWuHj0banF73saefF67XvR70gw= From: Thorsten Blum To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: Thorsten Blum , linux-kernel@vger.kernel.org Subject: [PATCH] x86/purgatory: Return bool from verify_sha256_digest() Date: Wed, 22 Jul 2026 18:22:45 +0200 Message-ID: <20260722162245.156368-2-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=1712; i=thorsten.blum@linux.dev; h=from:subject; bh=tBSocjZ0nsTDh/xrtReDm7hd/b4f+tgP/DNjMcBGXTs=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFkJ70LnL2EXULnwllmEJftuhnZSpLRvvEu6/LbpuxMn+ DC/O/yro5SFQYyLQVZMkeXBrB8zfEtrKjeZROyEmcPKBDKEgYtTACbiyMLwT4/fq41Fd/sMPcYL NwJZH/3Tvnj2/OT3XqLbtl3hj9vZwcbwT1V3gsAUm4kn7ujMW/4p6tQaZcOyiM2b03fIufdKfnn qxQwA 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. Also inline the verify_sha256_digest() check and remove the redundant local ret variable in purgatory(). Signed-off-by: Thorsten Blum --- arch/x86/purgatory/purgatory.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/arch/x86/purgatory/purgatory.c b/arch/x86/purgatory/purgatory.c index 655139dd0532..3ea8eb6af11f 100644 --- a/arch/x86/purgatory/purgatory.c +++ b/arch/x86/purgatory/purgatory.c @@ -21,7 +21,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; u8 digest[SHA256_DIGEST_SIZE]; @@ -31,22 +31,16 @@ static int verify_sha256_digest(void) 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))) - return 1; - - return 0; + return memcmp(digest, purgatory_sha256_digest, sizeof(digest)) == 0; } void purgatory(void) { - int ret; - - ret = verify_sha256_digest(); - if (ret) { + if (!verify_sha256_digest()) { /* loop forever */ for (;;) ;