Commit 233a2b14 authored by David S. Miller's avatar David S. Miller
Browse files

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: default avatarDavid S. Miller <davem@davemloft.net>
parents 26db4dbb 0584a917
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -1248,18 +1248,16 @@ static int a5psw_probe(struct platform_device *pdev)
	if (ret)
		goto clk_disable;

	mdio = of_get_child_by_name(dev->of_node, "mdio");
	if (of_device_is_available(mdio)) {
	mdio = of_get_available_child_by_name(dev->of_node, "mdio");
	if (mdio) {
		ret = a5psw_probe_mdio(a5psw, mdio);
		if (ret) {
		of_node_put(mdio);
		if (ret) {
			dev_err(dev, "Failed to register MDIO: %d\n", ret);
			goto hclk_disable;
		}
	}

	of_node_put(mdio);

	ds = &a5psw->ds;
	ds->dev = dev;
	ds->num_ports = A5PSW_PORTS_NUM;
+1 −5
Original line number Diff line number Diff line
@@ -468,13 +468,10 @@ int sja1105_mdiobus_register(struct dsa_switch *ds)
	if (rc)
		return rc;

	mdio_node = of_get_child_by_name(switch_node, "mdios");
	mdio_node = of_get_available_child_by_name(switch_node, "mdios");
	if (!mdio_node)
		return 0;

	if (!of_device_is_available(mdio_node))
		goto out_put_mdio_node;

	if (regs->mdio_100base_tx != SJA1105_RSV_ADDR) {
		rc = sja1105_mdiobus_base_tx_register(priv, mdio_node);
		if (rc)
@@ -487,7 +484,6 @@ int sja1105_mdiobus_register(struct dsa_switch *ds)
			goto err_free_base_tx_mdiobus;
	}

out_put_mdio_node:
	of_node_put(mdio_node);

	return 0;
+1 −6
Original line number Diff line number Diff line
@@ -1325,15 +1325,10 @@ static int owl_emac_mdio_init(struct net_device *netdev)
	struct device_node *mdio_node;
	int ret;

	mdio_node = of_get_child_by_name(dev->of_node, "mdio");
	mdio_node = of_get_available_child_by_name(dev->of_node, "mdio");
	if (!mdio_node)
		return -ENODEV;

	if (!of_device_is_available(mdio_node)) {
		ret = -ENODEV;
		goto err_put_node;
	}

	priv->mii = devm_mdiobus_alloc(dev);
	if (!priv->mii) {
		ret = -ENOMEM;
+1 −6
Original line number Diff line number Diff line
@@ -2554,17 +2554,12 @@ static int emac_dt_mdio_probe(struct emac_instance *dev)
	struct mii_bus *bus;
	int res;

	mii_np = of_get_child_by_name(dev->ofdev->dev.of_node, "mdio");
	mii_np = of_get_available_child_by_name(dev->ofdev->dev.of_node, "mdio");
	if (!mii_np) {
		dev_err(&dev->ofdev->dev, "no mdio definition found.");
		return -ENODEV;
	}

	if (!of_device_is_available(mii_np)) {
		res = -ENODEV;
		goto put_node;
	}

	bus = devm_mdiobus_alloc(&dev->ofdev->dev);
	if (!bus) {
		res = -ENOMEM;
+1 −6
Original line number Diff line number Diff line
@@ -830,17 +830,12 @@ static int mtk_mdio_init(struct mtk_eth *eth)
	int ret;
	u32 val;

	mii_np = of_get_child_by_name(eth->dev->of_node, "mdio-bus");
	mii_np = of_get_available_child_by_name(eth->dev->of_node, "mdio-bus");
	if (!mii_np) {
		dev_err(eth->dev, "no %s child node found", "mdio-bus");
		return -ENODEV;
	}

	if (!of_device_is_available(mii_np)) {
		ret = -ENODEV;
		goto err_put_node;
	}

	eth->mii_bus = devm_mdiobus_alloc(eth->dev);
	if (!eth->mii_bus) {
		ret = -ENOMEM;
Loading