From patchwork Thu Nov 20 02:56:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 756 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607470; bh=mNftQVvVogv3l9jyRZepWWgK4vxgUM5KxLRd7sOOtd4=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=N8gYCILRwjKkfkHgl83NA85htwFPCbs3nzmOy7lUxEEyIcJBQxUgGBEz1PWIRCxYl /4CA3jaFxcZRgwT6/4iPaFva1XwntgKJvW4F4Azp3mXubpfxKxwEBiDAIqnHvzoMml fI3KwBP5YG39QwcvZuDgOrK84Pd0BgFRTZ07YvIaJxZGsL+W11JklnWArK2GfPRVaa SG/h6BD4A3CNmZRPZx9whAPo/rRMTnrP5jp2FONJZQDrFbXKoVVcbfLPk4JwmzjiHE C1C2k2+iQlNw5cxQv1KRrcCgZD24uTNnQjINWAs7ardUerj/FUPzzPdO86J0qN5hEZ bzRq7kTOWTLXg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4C1AB686BB for ; Wed, 19 Nov 2025 19:57:50 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id vSPcq64sz5K2 for ; Wed, 19 Nov 2025 19:57:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607470; bh=mNftQVvVogv3l9jyRZepWWgK4vxgUM5KxLRd7sOOtd4=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=N8gYCILRwjKkfkHgl83NA85htwFPCbs3nzmOy7lUxEEyIcJBQxUgGBEz1PWIRCxYl /4CA3jaFxcZRgwT6/4iPaFva1XwntgKJvW4F4Azp3mXubpfxKxwEBiDAIqnHvzoMml fI3KwBP5YG39QwcvZuDgOrK84Pd0BgFRTZ07YvIaJxZGsL+W11JklnWArK2GfPRVaa SG/h6BD4A3CNmZRPZx9whAPo/rRMTnrP5jp2FONJZQDrFbXKoVVcbfLPk4JwmzjiHE C1C2k2+iQlNw5cxQv1KRrcCgZD24uTNnQjINWAs7ardUerj/FUPzzPdO86J0qN5hEZ bzRq7kTOWTLXg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3B02E68657 for ; Wed, 19 Nov 2025 19:57:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607467; bh=OWinCuv1DiJEpMJsFFM+8E+sglN06mM7979Md9hYOxU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jdSKIg8pgGDV41gRJmJTQMGCQFDi5zjv2G43gvv3gRIhzy0klGaEnjtpDC0xUHbL+ x6EZ+pbVjBqafpUgEeH2C3elD91kGMJU6A1qji61vWd34Xgp7992qWvAMwNA1RAjqm tXkamna7woMmvBO8bsFGBhvGZFpJz29OllH+Sh2Byzq0/Bz7GtcCQiKHxG42DSvpb4 QpezOavvohUp7aXGazN7rZ61JGerkZ7SgI8FvEKFgWiq7Ou/uGBKRyBvKJqdfyuNA6 ycS+nOtdyyFvyQ47PWD3mCTV8tr4IYNUe8ZtRL7fKk7oZofUOZRHp7IUf+2W4Y6g+s XWvk5SDAUONqA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6CF4268657; Wed, 19 Nov 2025 19:57:47 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id PcEqDrmJEX_w; Wed, 19 Nov 2025 19:57:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607466; bh=jHyW5mPRiUhxSITiGT1O2EXB/b15PrTjbYo3ktYiL9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oFBz39LZ5JIWHC5vfr/9dzVKHFIUFjCQ3JeC/HwGp0gyYZEdx6xI1DDM8i2WAibRt H4c8RBnJ7xAax8QFBilFwqDd/EX8aiLaQDqBOlDN4cZqWrVohmAJBLP0ITcjqJL0lm RtkbyP+tALI3GZY66bxFtPVIn0bJDcQhJIpFt0FIA15qfPlZomc/Cijo/Oe3ty6mmt do6g757lxBFfTwPoSp502A9yrW878KxWx4ZBwf8GL6dKH48oIrpCK/3FLh390AVu8A MBWLmT2T37YwgqHDMvRIWq4LXAkRFU9MDIMV+DGNhjvFrSxRTijXz7GQ6b+SyjpWj5 gNzF7KECxK0zQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 109F0686B2; Wed, 19 Nov 2025 19:57:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 19 Nov 2025 19:56:04 -0700 Message-ID: <20251120025614.2215587-30-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251120025614.2215587-1-sjg@u-boot.org> References: <20251120025614.2215587-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5TROJ5UC5BX7GIB62HQOSTYUW4PYT3MM X-Message-ID-Hash: 5TROJ5UC5BX7GIB62HQOSTYUW4PYT3MM X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 29/30] fit: Add a helper to iterate through hash/signature nodes List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass The pattern for iterating through and processing hash/signature subnodes is repeated in two places. Add a new process_subnodes() helper to reduce code duplication. Drop the now-unused ndepth and noffset local variables. Co-developed-by: Claude Signed-off-by: Simon Glass --- boot/fit_print.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/boot/fit_print.c b/boot/fit_print.c index 6772460a151..638f66942e9 100644 --- a/boot/fit_print.c +++ b/boot/fit_print.c @@ -283,6 +283,28 @@ static void fit_image_print_verification_data(struct fit_print_ctx *ctx, fit_image_print_data(ctx, noffset, "Sign"); } +/** + * process_subnodes() - process and print verification data for all subnodes + * @ctx: pointer to FIT print context + * @parent: parent node offset + * + * Iterates through all direct child nodes of the parent and prints their + * verification data (hash/signature information). + */ +static void process_subnodes(struct fit_print_ctx *ctx, int parent) +{ + const void *fit = ctx->fit; + int noffset; + int ndepth; + + for (ndepth = 0, noffset = fdt_next_node(fit, parent, &ndepth); + (noffset >= 0) && (ndepth > 0); + noffset = fdt_next_node(fit, noffset, &ndepth)) { + if (ndepth == 1) + fit_image_print_verification_data(ctx, noffset); + } +} + /** * fit_image_print - prints out the FIT component image details * @ctx: pointer to FIT print context @@ -305,8 +327,6 @@ void fit_image_print(struct fit_print_ctx *ctx, int image_noffset) size_t size; ulong load, entry; const void *data; - int noffset; - int ndepth; int ret; /* Mandatory properties */ @@ -366,14 +386,7 @@ void fit_image_print(struct fit_print_ctx *ctx, int image_noffset) } /* Process all hash subnodes of the component image node */ - for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth); - (noffset >= 0) && (ndepth > 0); - noffset = fdt_next_node(fit, noffset, &ndepth)) { - if (ndepth == 1) { - /* Direct child node of the component image node */ - fit_image_print_verification_data(ctx, noffset); - } - } + process_subnodes(ctx, image_noffset); } /** @@ -391,7 +404,6 @@ static void fit_conf_print(struct fit_print_ctx *ctx, int noffset) { const void *fit = ctx->fit; const char *uname; - int ndepth; /* Mandatory properties */ emit_desc(ctx, noffset, "Description"); @@ -408,14 +420,7 @@ static void fit_conf_print(struct fit_print_ctx *ctx, int noffset) emit_stringlist(ctx, noffset, FIT_COMPATIBLE_PROP, "Compatible"); /* Process all hash subnodes of the component configuration node */ - for (ndepth = 0, noffset = fdt_next_node(fit, noffset, &ndepth); - (noffset >= 0) && (ndepth > 0); - noffset = fdt_next_node(fit, noffset, &ndepth)) { - if (ndepth == 1) { - /* Direct child node of the component config node */ - fit_image_print_verification_data(ctx, noffset); - } - } + process_subnodes(ctx, noffset); } void fit_print(struct fit_print_ctx *ctx)