From: Shravya Kumbham <[email protected]>
check the return value of of_address_to_resource() and also add
missing of_node_put() for np and npp nodes.
Addresses-Coverity: Event check_return value.
Signed-off-by: Shravya Kumbham <[email protected]>
Signed-off-by: Radhey Shyam Pandey <[email protected]>
---
drivers/net/ethernet/xilinx/xilinx_emaclite.c | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/xilinx/xilinx_emaclite.c b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
index f9cf86e..c281423 100644
--- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
+++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
@@ -803,7 +803,7 @@ static int xemaclite_mdio_write(struct mii_bus *bus, int phy_id, int reg,
static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
{
struct mii_bus *bus;
- int rc;
+ int rc, ret;
struct resource res;
struct device_node *np = of_get_parent(lp->phy_node);
struct device_node *npp;
@@ -816,8 +816,14 @@ static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
return -ENODEV;
}
npp = of_get_parent(np);
-
- of_address_to_resource(npp, 0, &res);
+ ret = of_address_to_resource(npp, 0, &res);
+ of_node_put(npp);
+ if (ret) {
+ dev_err(dev, "%s resource error!\n",
+ dev->of_node->full_name);
+ of_node_put(np);
+ return ret;
+ }
if (lp->ndev->mem_start != res.start) {
struct phy_device *phydev;
@@ -827,6 +833,7 @@ static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
"MDIO of the phy is not registered yet\n");
else
put_device(&phydev->mdio.dev);
+ of_node_put(np);
return 0;
}
@@ -839,6 +846,7 @@ static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
bus = mdiobus_alloc();
if (!bus) {
dev_err(dev, "Failed to allocate mdiobus\n");
+ of_node_put(np);
return -ENOMEM;
}
@@ -851,6 +859,7 @@ static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
bus->parent = dev;
rc = of_mdiobus_register(bus, np);
+ of_node_put(np);
if (rc) {
dev_err(dev, "Failed to register mdio bus.\n");
goto err_register;
--
1.7.1
> -----Original Message-----
> From: Andrew Lunn <[email protected]>
> Sent: Friday, April 29, 2022 6:48 AM
> To: Radhey Shyam Pandey <[email protected]>
> Cc: [email protected]; [email protected]; [email protected]; Michal
> Simek <[email protected]>; [email protected]; linux-arm-
> [email protected]; [email protected]; git <[email protected]>;
> Shravya Kumbham <[email protected]>
> Subject: Re: [PATCH 2/2] net: emaclite: Add error handling for
> of_address_to_resource()
>
> On Thu, Apr 28, 2022 at 09:57:58PM +0530, Radhey Shyam Pandey wrote:
> > From: Shravya Kumbham <[email protected]>
> >
> > check the return value of of_address_to_resource() and also add
> > missing of_node_put() for np and npp nodes.
> >
> > Addresses-Coverity: Event check_return value.
> > Signed-off-by: Shravya Kumbham <[email protected]>
> > Signed-off-by: Radhey Shyam Pandey <[email protected]>
> > ---
> > drivers/net/ethernet/xilinx/xilinx_emaclite.c | 15 ++++++++++++---
> > 1 files changed, 12 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
> b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
> > index f9cf86e..c281423 100644
> > --- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
> > +++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
> > @@ -803,7 +803,7 @@ static int xemaclite_mdio_write(struct mii_bus *bus,
> int phy_id, int reg,
> > static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
> > {
> > struct mii_bus *bus;
> > - int rc;
> > + int rc, ret;
> > struct resource res;
> > struct device_node *np = of_get_parent(lp->phy_node);
> > struct device_node *npp;
>
> Reverse Chritmas tree is messed up here, but you could make it a bet
> less messed up by moving rc, ret further down.
Thanks, I will fix the existing declaration order in a new patch.
and in this patch will align new changes to reverse Christmas tree
order.
>
> Andrew
On Thu, Apr 28, 2022 at 09:57:58PM +0530, Radhey Shyam Pandey wrote:
> From: Shravya Kumbham <[email protected]>
>
> check the return value of of_address_to_resource() and also add
> missing of_node_put() for np and npp nodes.
>
> Addresses-Coverity: Event check_return value.
> Signed-off-by: Shravya Kumbham <[email protected]>
> Signed-off-by: Radhey Shyam Pandey <[email protected]>
> ---
> drivers/net/ethernet/xilinx/xilinx_emaclite.c | 15 ++++++++++++---
> 1 files changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/xilinx/xilinx_emaclite.c b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
> index f9cf86e..c281423 100644
> --- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
> +++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
> @@ -803,7 +803,7 @@ static int xemaclite_mdio_write(struct mii_bus *bus, int phy_id, int reg,
> static int xemaclite_mdio_setup(struct net_local *lp, struct device *dev)
> {
> struct mii_bus *bus;
> - int rc;
> + int rc, ret;
> struct resource res;
> struct device_node *np = of_get_parent(lp->phy_node);
> struct device_node *npp;
Reverse Chritmas tree is messed up here, but you could make it a bet
less messed up by moving rc, ret further down.
Andrew