2021-10-15 13:45:16

by Jiabing Wan

[permalink] [raw]
Subject: [PATCH] net: ethernet: ti: Add of_node_put() before return

Fix following coccicheck warning:
./drivers/net/ethernet/ti/am65-cpsw-nuss.c:1835:1-23: WARNING: Function
for_each_child_of_node should have of_node_put() before return

Early exits from for_each_child_of_node should decrement the
node reference counter.

Signed-off-by: Wan Jiabing <[email protected]>
---
drivers/net/ethernet/ti/am65-cpsw-nuss.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
index 6904bfaa5777..00ef27cdde84 100644
--- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
@@ -1844,12 +1844,14 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
if (ret < 0) {
dev_err(dev, "%pOF error reading port_id %d\n",
port_np, ret);
+ of_node_put(port_np);
return ret;
}

if (!port_id || port_id > common->port_num) {
dev_err(dev, "%pOF has invalid port_id %u %s\n",
port_np, port_id, port_np->name);
+ of_node_put(port_np);
return -EINVAL;
}

@@ -1866,8 +1868,10 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
(AM65_CPSW_NU_FRAM_PORT_OFFSET * (port_id - 1));

port->slave.mac_sl = cpsw_sl_get("am65", dev, port->port_base);
- if (IS_ERR(port->slave.mac_sl))
+ if (IS_ERR(port->slave.mac_sl)) {
+ of_node_put(port_np);
return PTR_ERR(port->slave.mac_sl);
+ }

port->disabled = !of_device_is_available(port_np);
if (port->disabled) {
@@ -1880,6 +1884,7 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
ret = PTR_ERR(port->slave.ifphy);
dev_err(dev, "%pOF error retrieving port phy: %d\n",
port_np, ret);
+ of_node_put(port_np);
return ret;
}

@@ -1889,10 +1894,12 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
/* get phy/link info */
if (of_phy_is_fixed_link(port_np)) {
ret = of_phy_register_fixed_link(port_np);
- if (ret)
+ if (ret) {
+ of_node_put(port_np);
return dev_err_probe(dev, ret,
"failed to register fixed-link phy %pOF\n",
port_np);
+ }
port->slave.phy_node = of_node_get(port_np);
} else {
port->slave.phy_node =
@@ -1902,6 +1909,7 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
if (!port->slave.phy_node) {
dev_err(dev,
"slave[%d] no phy found\n", port_id);
+ of_node_put(port_np);
return -ENODEV;
}

@@ -1909,6 +1917,7 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
if (ret) {
dev_err(dev, "%pOF read phy-mode err %d\n",
port_np, ret);
+ of_node_put(port_np);
return ret;
}

--
2.20.1