Skip to content

Commit 7a6bc33

Browse files
Shravya KumbhamPaolo Abeni
authored andcommitted
net: emaclite: Add error handling for of_address_to_resource()
check the return value of of_address_to_resource() and also add missing of_node_put() for np and npp nodes. Fixes: e0a3bc6 ("net: emaclite: Support multiple phys connected to one MDIO bus") Addresses-Coverity: Event check_return value. Signed-off-by: Shravya Kumbham <[email protected]> Signed-off-by: Radhey Shyam Pandey <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent b800528 commit 7a6bc33

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/net/ethernet/xilinx/xilinx_emaclite.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,10 @@ static int xemaclite_mdio_write(struct mii_bus *bus, int phy_id, int reg,
823823
static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
824824
{
825825
struct mii_bus *bus;
826-
int rc;
827826
struct resource res;
828827
struct device_node *np = of_get_parent(lp->phy_node);
829828
struct device_node *npp;
829+
int rc, ret;
830830

831831
/* Don't register the MDIO bus if the phy_node or its parent node
832832
* can't be found.
@@ -836,8 +836,14 @@ static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
836836
return -ENODEV;
837837
}
838838
npp = of_get_parent(np);
839-
840-
of_address_to_resource(npp, 0, &res);
839+
ret = of_address_to_resource(npp, 0, &res);
840+
of_node_put(npp);
841+
if (ret) {
842+
dev_err(dev, "%s resource error!\n",
843+
dev->of_node->full_name);
844+
of_node_put(np);
845+
return ret;
846+
}
841847
if (lp->ndev->mem_start != res.start) {
842848
struct phy_device *phydev;
843849
phydev = of_phy_find_device(lp->phy_node);
@@ -846,6 +852,7 @@ static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
846852
"MDIO of the phy is not registered yet\n");
847853
else
848854
put_device(&phydev->mdio.dev);
855+
of_node_put(np);
849856
return 0;
850857
}
851858

@@ -858,6 +865,7 @@ static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
858865
bus = mdiobus_alloc();
859866
if (!bus) {
860867
dev_err(dev, "Failed to allocate mdiobus\n");
868+
of_node_put(np);
861869
return -ENOMEM;
862870
}
863871

@@ -870,6 +878,7 @@ static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
870878
bus->parent = dev;
871879

872880
rc = of_mdiobus_register(bus, np);
881+
of_node_put(np);
873882
if (rc) {
874883
dev_err(dev, "Failed to register mdio bus.\n");
875884
goto err_register;

0 commit comments

Comments
 (0)