]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: gianfar: Use device_get_named_child_node_count()
authorMatti Vaittinen <mazziesaccount@gmail.com>
Wed, 18 Jun 2025 12:22:02 +0000 (15:22 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 19 Jun 2025 22:36:21 +0000 (15:36 -0700)
We can avoid open-coding the loop construct which counts firmware child
nodes with a specific name by using the newly added
device_get_named_child_node_count().

The gianfar driver has such open-coded loop. Replace it with the
device_get_child_node_count_named().

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/3a33988fc042588cb00a0bfc5ad64e749cb0eb1f.1750248902.git.mazziesaccount@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/freescale/gianfar.c

index bcbcad61351227dbc666f132a27b4b6154c45645..7c0f049f09384c0b3d3aeeab9496b9817f99ba8a 100644 (file)
@@ -97,6 +97,7 @@
 #include <linux/phy_fixed.h>
 #include <linux/of.h>
 #include <linux/of_net.h>
+#include <linux/property.h>
 
 #include "gianfar.h"
 
@@ -571,18 +572,6 @@ static int gfar_parse_group(struct device_node *np,
        return 0;
 }
 
-static int gfar_of_group_count(struct device_node *np)
-{
-       struct device_node *child;
-       int num = 0;
-
-       for_each_available_child_of_node(np, child)
-               if (of_node_name_eq(child, "queue-group"))
-                       num++;
-
-       return num;
-}
-
 /* Reads the controller's registers to determine what interface
  * connects it to the PHY.
  */
@@ -654,8 +643,10 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
                num_rx_qs = 1;
        } else { /* MQ_MG_MODE */
                /* get the actual number of supported groups */
-               unsigned int num_grps = gfar_of_group_count(np);
+               unsigned int num_grps;
 
+               num_grps = device_get_named_child_node_count(&ofdev->dev,
+                                                            "queue-group");
                if (num_grps == 0 || num_grps > MAXGROUPS) {
                        dev_err(&ofdev->dev, "Invalid # of int groups(%d)\n",
                                num_grps);