From patchwork Wed Jul 31 14:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 815656 Delivered-To: patch@linaro.org Received: by 2002:a5d:4acf:0:b0:367:895a:4699 with SMTP id y15csp780235wrs; Wed, 31 Jul 2024 07:55:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWmMWLVm6JAKRrUDGiTWwruS9CS9/OG6+5m0/x3GGonq7YKY48eGITF4wm1106diMV9cjVRRRtubIbRJAGHVWIv X-Google-Smtp-Source: AGHT+IHkRagmn+elgDj3aLGuSVCohLcO+wwIh+LIZhIk2GN6rUR6G3GtP7Wk+Yb4mbsV6czI315w X-Received: by 2002:a17:907:2d86:b0:a77:b0a4:7d88 with SMTP id a640c23a62f3a-a7d3fdb79e8mr1216842866b.10.1722437744461; Wed, 31 Jul 2024 07:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722437744; cv=none; d=google.com; s=arc-20160816; b=GCv5fYO3I9XLYJ6P8Gc0QhkwVek0kqKGHeQqjsJWsysotn5w6gwL0Bf2vM+fksHFM4 fzmYGBWRRBMoliawmQ9gSVPiefX1tl2gB92iMBBgTKalhs2AS0OPwFWrZBgSLTaCgqBj iSojJGYRpgOfd42sBWOSDBo0K/zkkSz9yKI/IWqkpF7hzAUHfBIRkQ52rXnfjPtsUL9U Cy63Si++DIzKlXi6Vq6q/6sAZK5JD4RxsFZ+cpfdk6RyC1rjiuIHbVJ4C9TyiZM27hY4 mMJhT5U0Vit+1hwvW30n2+8wknOOOMgLuh1CSUZtiM70iEiL9UEeCcB+vNkqIv4Fa9KH GLAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=n83COCECWlwqkDyJHxhSliGqunSQaGmNJuKVDC+BNDI=; fh=c60fu1IChZaOc2lQYQAOoRysAfBqXosZh6e58mdWpwk=; b=skHpl40FOJlW0fVQvE/G8ucBA7UOzPXXrYVN92Gqp7D5kwSEtZ5cxz+1MnBh+sC0nZ wEpKcpmp9CHS8eW9btzMneaA4yb2rj+OtPoMn5EQkep/EhOR1yJ2dX00JoAMg6CSIvBl h1FmLtbHurpe3LAUbVLvMZMCsF3Yx6+L3maSfQo5v09jBcpoWPk2JH2c1k0wLoarSCgI 97Vbl49nWVtkoM2LY+yxhHCPTxKO9l5+b4rd9lsZ/hY1ZxQsjOtOuX0F8dSglvOyLeoY 5hSYHT76JMcbsZBizxq1AtliIt0diYiQt2pMZmNZRbW3SFnMnhUxPo78ftzAwYy8/p/F lrZw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a7aca902257si937534466b.235.2024.07.31.07.55.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 07:55:44 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 60F16889D5; Wed, 31 Jul 2024 16:55:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 5DCA1889D9; Wed, 31 Jul 2024 16:55:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 1555B8881B for ; Wed, 31 Jul 2024 16:55:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C17291007; Wed, 31 Jul 2024 07:56:04 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4A4913F5A1; Wed, 31 Jul 2024 07:55:37 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Sughosh Ganu Subject: [PATCH] list: use list_count_nodes() to count list entries Date: Wed, 31 Jul 2024 20:25:21 +0530 Message-Id: <20240731145521.19527-1-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Use the API function list_count_nodes() to count the number of list entries. Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass --- Note: To be applied on top of efi-2024-10-rc2 boot/scene.c | 8 +------- drivers/mtd/ubi/fastmap.c | 8 +++----- fs/yaffs2/yaffs_guts.c | 5 ++--- lib/efi_loader/efi_boottime.c | 4 +--- lib/fwu_updates/fwu_mtd.c | 5 +---- test/boot/expo.c | 4 +--- 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/boot/scene.c b/boot/scene.c index ac976aa26b..270c9c6723 100644 --- a/boot/scene.c +++ b/boot/scene.c @@ -79,13 +79,7 @@ int scene_title_set(struct scene *scn, uint id) int scene_obj_count(struct scene *scn) { - struct scene_obj *obj; - int count = 0; - - list_for_each_entry(obj, &scn->obj_head, sibling) - count++; - - return count; + return list_count_nodes(&scn->obj_head); } void *scene_obj_find(const struct scene *scn, uint id, enum scene_obj_t type) diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index 21750e1817..9c6b15b8cb 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c @@ -581,13 +581,11 @@ static int count_fastmap_pebs(struct ubi_attach_info *ai) struct ubi_ainf_peb *aeb; struct ubi_ainf_volume *av; struct rb_node *rb1, *rb2; - int n = 0; + int n; - list_for_each_entry(aeb, &ai->erase, u.list) - n++; + n = list_count_nodes(&ai->erase); - list_for_each_entry(aeb, &ai->free, u.list) - n++; + n += list_count_nodes(&ai->free); ubi_rb_for_each_entry(rb1, av, &ai->volumes, rb) ubi_rb_for_each_entry(rb2, aeb, &av->root, u.rb) diff --git a/fs/yaffs2/yaffs_guts.c b/fs/yaffs2/yaffs_guts.c index e89d02513c..c20f2f8298 100644 --- a/fs/yaffs2/yaffs_guts.c +++ b/fs/yaffs2/yaffs_guts.c @@ -4452,13 +4452,12 @@ loff_t yaffs_get_obj_length(struct yaffs_obj *obj) int yaffs_get_obj_link_count(struct yaffs_obj *obj) { int count = 0; - struct list_head *i; if (!obj->unlinked) count++; /* the object itself */ - list_for_each(i, &obj->hard_links) - count++; /* add the hard links; */ + /* add the hard links; */ + count += list_count_nodes(&obj->hard_links); return count; } diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index eedc5f3954..a8b8f71a0a 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2516,9 +2516,7 @@ static efi_status_t EFIAPI efi_protocols_per_handle( return EFI_EXIT(EFI_INVALID_PARAMETER); /* Count protocols */ - list_for_each(protocol_handle, &efiobj->protocols) { - ++*protocol_buffer_count; - } + *protocol_buffer_count = list_count_nodes(&efiobj->protocols); /* Copy GUIDs */ if (*protocol_buffer_count) { diff --git a/lib/fwu_updates/fwu_mtd.c b/lib/fwu_updates/fwu_mtd.c index ccaba3f311..c14203b9dd 100644 --- a/lib/fwu_updates/fwu_mtd.c +++ b/lib/fwu_updates/fwu_mtd.c @@ -60,10 +60,7 @@ int fwu_mtd_get_alt_num(efi_guid_t *image_id, u8 *alt_num, if (ret) return -ENOENT; - nalt = 0; - list_for_each_entry(dfu, &dfu_list, list) - nalt++; - + nalt = list_count_nodes(&dfu_list); if (!nalt) { log_warning("No entities in dfu_alt_info\n"); dfu_free_entities(); diff --git a/test/boot/expo.c b/test/boot/expo.c index 6ea0184373..6ad4395841 100644 --- a/test/boot/expo.c +++ b/test/boot/expo.c @@ -703,9 +703,7 @@ static int expo_test_build(struct unit_test_state *uts) txt = scene_obj_find(scn, item->label_id, SCENEOBJT_NONE); ut_asserteq_str("2 GHz", expo_get_str(exp, txt->str_id)); - count = 0; - list_for_each_entry(item, &menu->item_head, sibling) - count++; + count = list_count_nodes(&menu->item_head); ut_asserteq(3, count); expo_destroy(exp);