]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: use list_count_nodes() for counting list nodes
authorSughosh Ganu <sughosh.ganu@linaro.org>
Tue, 30 Jul 2024 11:11:32 +0000 (16:41 +0530)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Wed, 31 Jul 2024 07:54:53 +0000 (09:54 +0200)
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 <sughosh.ganu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
drivers/core/util.c
include/dm/util.h
test/dm/bus.c
test/dm/core.c
test/dm/test-fdt.c

index 108a3bc4dac14c41ae22466fe195595ab2b8babb..fa893485a09533d040d4d24c583aedda21de6fc9 100644 (file)
@@ -3,23 +3,13 @@
  * Copyright (c) 2013 Google, Inc
  */
 
+#include <vsprintf.h>
 #include <dm/device.h>
 #include <dm/ofnode.h>
 #include <dm/read.h>
 #include <dm/util.h>
 #include <linux/libfdt.h>
-#include <vsprintf.h>
-
-int list_count_items(struct list_head *head)
-{
-       struct list_head *node;
-       int count = 0;
-
-       list_for_each(node, head)
-               count++;
-
-       return count;
-}
+#include <linux/list.h>
 
 #if CONFIG_IS_ENABLED(OF_REAL)
 int pci_get_devfn(struct udevice *dev)
index 95c3527a37cf4baf5a66463e38dbe223adb0aa49..ec518c51d93ab00562dfe4e2993e9c1997c4af89 100644 (file)
@@ -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
  *
index a338c7f567c1183a622d9125d6be7ca3ff938561..95326f23dadaf4799fc69dfc5937df6bbe6e2ab0 100644 (file)
@@ -14,6 +14,7 @@
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
 #include <dm/util.h>
+#include <linux/list.h>
 #include <test/test.h>
 #include <test/ut.h>
 
@@ -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));
 
index dbad1b317db7912db74e0c86fa9d32a215d987ee..5bc5e8e82ecd082cc1e66fa4591ad33a1c30b5f6 100644 (file)
@@ -16,6 +16,7 @@
 #include <dm/util.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
+#include <linux/list.h>
 #include <test/test.h>
 #include <test/ut.h>
 
@@ -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]);
index 18c89eef43fce6a03dff7693e1b004e303737fa1..31effff59c2194d290a57dca8d93ff02e7bdae82 100644 (file)
@@ -19,6 +19,7 @@
 #include <dm/util.h>
 #include <dm/of_access.h>
 #include <linux/ioport.h>
+#include <linux/list.h>
 #include <test/test.h>
 #include <test/ut.h>
 
@@ -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;
 }