From patchwork Tue Jul 30 11:11:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 815304 Delivered-To: patch@linaro.org Received: by 2002:a5d:4acf:0:b0:367:895a:4699 with SMTP id y15csp242963wrs; Tue, 30 Jul 2024 04:12:39 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVSW04pUUes7lbMWy7tDm3caprHEQZo7a6mfE14ykJVtZH8R70R7jzFWKUwmp4f4l9YzwCNXvxDmkh/1YWjqU6U X-Google-Smtp-Source: AGHT+IF5fZME5UFbk7oP5u0WxR65zFrfh/wTcvg8GKmoLOIIILeo7ATmJWyFZQbj9vmRNuHH0utB X-Received: by 2002:a17:907:3eaa:b0:a7a:a7b8:adb1 with SMTP id a640c23a62f3a-a7d40073465mr729103366b.36.1722337959236; Tue, 30 Jul 2024 04:12:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722337959; cv=none; d=google.com; s=arc-20160816; b=K3NZr7BKEc9k2NUafjokr087dMJhO+W/K4IxUeFm78p/0ZD31N2asjSneyPpvb+IVG u0rg+1U8tBle2dQA4+3ZzmqHe3Xl+beAIfzluWMuykkzS10OftDYBIT92GCLErsJ1C9S 9fZ2LT2N16Tr8hpn28aEf+XCjI5r04TevDVESPavD8K+/RIyRUPxSw5T0mg8UHSax3S0 Du4hAg9oYZbuv/gc/zcOMuDMLo7MguBgSaJ8pgL8PNqr0cTc5rSJNvoycu8Fr/7PnDP8 g6T+UQxONmdEIjmMeXSbLUugoN5+iAxKVB6T9Q2c8OvPBj2nxJD1dKtYuBcXbYHssI76 cEZQ== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=Jx+nLp6Woit5hLSa4PYJWnkr7dFQ1W+mkFVFVjbEUHA=; fh=c60fu1IChZaOc2lQYQAOoRysAfBqXosZh6e58mdWpwk=; b=y/vldxq0XbVtHTEIP3bEvYZvDv4VuMNdB8skHpd6cy97WcgsidGUZZD1eXMT5UPlux pxi4vyfEHVyMinfTk0tgQqEnnLo0z5t+mvNrgvqBfSkUgxKLzl32fcJQc31BZwzW4yLB hQ9RGH0/f1b9CqeB0jraTgcoVrZrgtHWO3WkYC8cxHnw5R3XJxbLHg2SG+uSaiasRiIL 12NsOLmltUBaTempkaDF6+2MJZErFaf2depggZWQbdmSFwRjhmvxyzfkIrYSQPKl/fn7 7jO9AGc3wsO8DECAbtzO8FVMcpj3v/TU6ZMa35VJeY9Tusl7Y8C4ccaEJx1MF73Vap5G gqrw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-a7acac63dd0si775747566b.649.2024.07.30.04.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 04:12:39 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 97F5288827; Tue, 30 Jul 2024 13:12:07 +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 6F07A8881D; Tue, 30 Jul 2024 13:12:06 +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 46E8288860 for ; Tue, 30 Jul 2024 13:12:04 +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 60F381007; Tue, 30 Jul 2024 04:12:29 -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 175AA3F5A1; Tue, 30 Jul 2024 04:12:01 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Sughosh Ganu Subject: [PATCH 5/5] dm: use list_count_nodes() for counting list nodes Date: Tue, 30 Jul 2024 16:41:32 +0530 Message-Id: <20240730111132.1097315-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240730111132.1097315-1-sughosh.ganu@linaro.org> References: <20240730111132.1097315-1-sughosh.ganu@linaro.org> 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 The linux kernel has the list_count_nodes() API functions which is used for counting nodes of a list. This has now been imported in U-Boot as part of an earlier commit. Use this function and drop the list_count_items(). Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- drivers/core/util.c | 14 ++------------ include/dm/util.h | 8 -------- test/dm/bus.c | 5 +++-- test/dm/core.c | 9 +++++---- test/dm/test-fdt.c | 5 +++-- 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/drivers/core/util.c b/drivers/core/util.c index 108a3bc4da..fa893485a0 100644 --- a/drivers/core/util.c +++ b/drivers/core/util.c @@ -3,23 +3,13 @@ * Copyright (c) 2013 Google, Inc */ +#include #include #include #include #include #include -#include - -int list_count_items(struct list_head *head) -{ - struct list_head *node; - int count = 0; - - list_for_each(node, head) - count++; - - return count; -} +#include #if CONFIG_IS_ENABLED(OF_REAL) int pci_get_devfn(struct udevice *dev) diff --git a/include/dm/util.h b/include/dm/util.h index 95c3527a37..ec518c51d9 100644 --- a/include/dm/util.h +++ b/include/dm/util.h @@ -16,14 +16,6 @@ struct dm_stats; struct list_head; -/** - * list_count_items() - Count number of items in a list - * - * @param head: Head of list - * Return: number of items, or 0 if empty - */ -int list_count_items(struct list_head *head); - /** * Dump out a tree of all devices starting @uclass * diff --git a/test/dm/bus.c b/test/dm/bus.c index a338c7f567..95326f23da 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -27,14 +28,14 @@ static int dm_test_bus_children(struct unit_test_state *uts) struct uclass *uc; ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc)); - ut_asserteq(num_devices, list_count_items(&uc->dev_head)); + ut_asserteq(num_devices, list_count_nodes(&uc->dev_head)); /* Probe the bus, which should yield 3 more devices */ ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); num_devices += 3; ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc)); - ut_asserteq(num_devices, list_count_items(&uc->dev_head)); + ut_asserteq(num_devices, list_count_nodes(&uc->dev_head)); ut_assert(!dm_check_devices(uts, num_devices)); diff --git a/test/dm/core.c b/test/dm/core.c index dbad1b317d..5bc5e8e82e 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -123,15 +124,15 @@ static int dm_test_autobind(struct unit_test_state *uts) * device with no children. */ ut_assert(uts->root); - ut_asserteq(1, list_count_items(gd->uclass_root)); - ut_asserteq(0, list_count_items(&gd->dm_root->child_head)); + ut_asserteq(1, list_count_nodes(gd->uclass_root)); + ut_asserteq(0, list_count_nodes(&gd->dm_root->child_head)); ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]); ut_assertok(dm_scan_plat(false)); /* We should have our test class now at least, plus more children */ - ut_assert(1 < list_count_items(gd->uclass_root)); - ut_assert(0 < list_count_items(&gd->dm_root->child_head)); + ut_assert(1 < list_count_nodes(gd->uclass_root)); + ut_assert(0 < list_count_nodes(&gd->dm_root->child_head)); /* Our 3 dm_test_infox children should be bound to the test uclass */ ut_asserteq(3, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]); diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 18c89eef43..31effff59c 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -162,7 +163,7 @@ static int dm_test_fdt(struct unit_test_state *uts) ut_assert(!ret); /* These are num_devices compatible root-level device tree nodes */ - ut_asserteq(num_devices, list_count_items(&uc->dev_head)); + ut_asserteq(num_devices, list_count_nodes(&uc->dev_head)); /* Each should have platform data but no private data */ for (i = 0; i < num_devices; i++) { @@ -217,7 +218,7 @@ static int dm_test_fdt_pre_reloc(struct unit_test_state *uts) * one with "bootph-all" property (a-test node), and the other * one whose driver marked with DM_FLAG_PRE_RELOC flag (h-test node). */ - ut_asserteq(2, list_count_items(&uc->dev_head)); + ut_asserteq(2, list_count_nodes(&uc->dev_head)); return 0; }