Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'of_get_available_child_by_name'

Biju Das says:

====================
Add of_get_available_child_by_name()

There are lot of net drivers using of_get_child_by_name() followed by
of_device_is_available() to find the available child node by name for a
given parent. Provide a helper for these users to simplify the code.

v1->v2:
* Make it as a series as per [1] to cover the dependency.
* Added Rb tag from Rob for patch#1 and this patch can be merged through
net as it is the main user.
* Updated all the patches with patch suffix net-next
* Dropped _free() usage.

[1]
https://lore.kernel.org/all/CAL_JsqLo4uSGYMcLXN=0iSUMHdW8RaGCY+o8ThQHq3_eUTV9wQ@mail.gmail.com/
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+44 -34
+3 -5
drivers/net/dsa/rzn1_a5psw.c
··· 1248 1248 if (ret) 1249 1249 goto clk_disable; 1250 1250 1251 - mdio = of_get_child_by_name(dev->of_node, "mdio"); 1252 - if (of_device_is_available(mdio)) { 1251 + mdio = of_get_available_child_by_name(dev->of_node, "mdio"); 1252 + if (mdio) { 1253 1253 ret = a5psw_probe_mdio(a5psw, mdio); 1254 + of_node_put(mdio); 1254 1255 if (ret) { 1255 - of_node_put(mdio); 1256 1256 dev_err(dev, "Failed to register MDIO: %d\n", ret); 1257 1257 goto hclk_disable; 1258 1258 } 1259 1259 } 1260 - 1261 - of_node_put(mdio); 1262 1260 1263 1261 ds = &a5psw->ds; 1264 1262 ds->dev = dev;
+1 -5
drivers/net/dsa/sja1105/sja1105_mdio.c
··· 468 468 if (rc) 469 469 return rc; 470 470 471 - mdio_node = of_get_child_by_name(switch_node, "mdios"); 471 + mdio_node = of_get_available_child_by_name(switch_node, "mdios"); 472 472 if (!mdio_node) 473 473 return 0; 474 - 475 - if (!of_device_is_available(mdio_node)) 476 - goto out_put_mdio_node; 477 474 478 475 if (regs->mdio_100base_tx != SJA1105_RSV_ADDR) { 479 476 rc = sja1105_mdiobus_base_tx_register(priv, mdio_node); ··· 484 487 goto err_free_base_tx_mdiobus; 485 488 } 486 489 487 - out_put_mdio_node: 488 490 of_node_put(mdio_node); 489 491 490 492 return 0;
+1 -6
drivers/net/ethernet/actions/owl-emac.c
··· 1325 1325 struct device_node *mdio_node; 1326 1326 int ret; 1327 1327 1328 - mdio_node = of_get_child_by_name(dev->of_node, "mdio"); 1328 + mdio_node = of_get_available_child_by_name(dev->of_node, "mdio"); 1329 1329 if (!mdio_node) 1330 1330 return -ENODEV; 1331 - 1332 - if (!of_device_is_available(mdio_node)) { 1333 - ret = -ENODEV; 1334 - goto err_put_node; 1335 - } 1336 1331 1337 1332 priv->mii = devm_mdiobus_alloc(dev); 1338 1333 if (!priv->mii) {
+1 -6
drivers/net/ethernet/ibm/emac/core.c
··· 2554 2554 struct mii_bus *bus; 2555 2555 int res; 2556 2556 2557 - mii_np = of_get_child_by_name(dev->ofdev->dev.of_node, "mdio"); 2557 + mii_np = of_get_available_child_by_name(dev->ofdev->dev.of_node, "mdio"); 2558 2558 if (!mii_np) { 2559 2559 dev_err(&dev->ofdev->dev, "no mdio definition found."); 2560 2560 return -ENODEV; 2561 - } 2562 - 2563 - if (!of_device_is_available(mii_np)) { 2564 - res = -ENODEV; 2565 - goto put_node; 2566 2561 } 2567 2562 2568 2563 bus = devm_mdiobus_alloc(&dev->ofdev->dev);
+1 -6
drivers/net/ethernet/mediatek/mtk_eth_soc.c
··· 830 830 int ret; 831 831 u32 val; 832 832 833 - mii_np = of_get_child_by_name(eth->dev->of_node, "mdio-bus"); 833 + mii_np = of_get_available_child_by_name(eth->dev->of_node, "mdio-bus"); 834 834 if (!mii_np) { 835 835 dev_err(eth->dev, "no %s child node found", "mdio-bus"); 836 836 return -ENODEV; 837 - } 838 - 839 - if (!of_device_is_available(mii_np)) { 840 - ret = -ENODEV; 841 - goto err_put_node; 842 837 } 843 838 844 839 eth->mii_bus = devm_mdiobus_alloc(eth->dev);
+1 -6
drivers/net/ethernet/mediatek/mtk_star_emac.c
··· 1427 1427 1428 1428 of_node = dev->of_node; 1429 1429 1430 - mdio_node = of_get_child_by_name(of_node, "mdio"); 1430 + mdio_node = of_get_available_child_by_name(of_node, "mdio"); 1431 1431 if (!mdio_node) 1432 1432 return -ENODEV; 1433 - 1434 - if (!of_device_is_available(mdio_node)) { 1435 - ret = -ENODEV; 1436 - goto out_put_node; 1437 - } 1438 1433 1439 1434 priv->mii = devm_mdiobus_alloc(dev); 1440 1435 if (!priv->mii) {
+27
drivers/of/base.c
··· 824 824 } 825 825 EXPORT_SYMBOL(of_get_child_by_name); 826 826 827 + /** 828 + * of_get_available_child_by_name - Find the available child node by name for a given parent 829 + * @node: parent node 830 + * @name: child name to look for. 831 + * 832 + * This function looks for child node for given matching name and checks the 833 + * device's availability for use. 834 + * 835 + * Return: A node pointer if found, with refcount incremented, use 836 + * of_node_put() on it when done. 837 + * Returns NULL if node is not found. 838 + */ 839 + struct device_node *of_get_available_child_by_name(const struct device_node *node, 840 + const char *name) 841 + { 842 + struct device_node *child; 843 + 844 + child = of_get_child_by_name(node, name); 845 + if (child && !of_device_is_available(child)) { 846 + of_node_put(child); 847 + return NULL; 848 + } 849 + 850 + return child; 851 + } 852 + EXPORT_SYMBOL(of_get_available_child_by_name); 853 + 827 854 struct device_node *__of_find_node_by_path(const struct device_node *parent, 828 855 const char *path) 829 856 {
+9
include/linux/of.h
··· 301 301 const char *compatible); 302 302 extern struct device_node *of_get_child_by_name(const struct device_node *node, 303 303 const char *name); 304 + extern struct device_node *of_get_available_child_by_name(const struct device_node *node, 305 + const char *name); 304 306 305 307 /* cache lookup */ 306 308 extern struct device_node *of_find_next_cache_node(const struct device_node *); ··· 574 572 } 575 573 576 574 static inline struct device_node *of_get_child_by_name( 575 + const struct device_node *node, 576 + const char *name) 577 + { 578 + return NULL; 579 + } 580 + 581 + static inline struct device_node *of_get_available_child_by_name( 577 582 const struct device_node *node, 578 583 const char *name) 579 584 {