All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: mdiobus: remove unneccessary fwnode_handle_put() in the error path
@ 2022-11-30  9:17 Yang Yingliang
  2022-12-01  2:41 ` Andrew Lunn
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2022-11-30  9:17 UTC (permalink / raw)
  To: netdev
  Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
	ioana.ciornei, calvin.johnson, grant.likely, zengheng4

If phy_device_register() or fwnode_mdiobus_phy_device_register()
fail, phy_device_free() is called, the device refcount is decreased
to 0, then fwnode_handle_put() is called in phy_device_release(),
so the fwnode_handle_put() in the error path can be removed to avoid
double put.

Fixes: cdde1560118f ("net: mdiobus: fix unbalanced node reference count")
Reported-by: Zeng Heng <zengheng4@huawei.com>
Tested-by: Zeng Heng <zengheng4@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/net/mdio/fwnode_mdio.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c
index eb344f6d4a7b..e584abda585b 100644
--- a/drivers/net/mdio/fwnode_mdio.c
+++ b/drivers/net/mdio/fwnode_mdio.c
@@ -97,10 +97,8 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,
 	 * register it
 	 */
 	rc = phy_device_register(phy);
-	if (rc) {
-		fwnode_handle_put(child);
+	if (rc)
 		return rc;
-	}
 
 	dev_dbg(&mdio->dev, "registered phy %p fwnode at address %i\n",
 		child, addr);
@@ -152,10 +150,8 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
 
 		/* All data is now stored in the phy struct, so register it */
 		rc = phy_device_register(phy);
-		if (rc) {
-			fwnode_handle_put(phy->mdio.dev.fwnode);
+		if (rc)
 			goto clean_phy;
-		}
 	} else if (is_of_node(child)) {
 		rc = fwnode_mdiobus_phy_device_register(bus, phy, child, addr);
 		if (rc)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] net: mdiobus: remove unneccessary fwnode_handle_put() in the error path
  2022-11-30  9:17 [PATCH net] net: mdiobus: remove unneccessary fwnode_handle_put() in the error path Yang Yingliang
@ 2022-12-01  2:41 ` Andrew Lunn
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2022-12-01  2:41 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: netdev, hkallweit1, linux, davem, edumazet, kuba, pabeni,
	ioana.ciornei, calvin.johnson, grant.likely, zengheng4

On Wed, Nov 30, 2022 at 05:17:59PM +0800, Yang Yingliang wrote:
> If phy_device_register() or fwnode_mdiobus_phy_device_register()
> fail, phy_device_free() is called, the device refcount is decreased
> to 0, then fwnode_handle_put() is called in phy_device_release(),
> so the fwnode_handle_put() in the error path can be removed to avoid
> double put.
> 
> Fixes: cdde1560118f ("net: mdiobus: fix unbalanced node reference count")
> Reported-by: Zeng Heng <zengheng4@huawei.com>
> Tested-by: Zeng Heng <zengheng4@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  drivers/net/mdio/fwnode_mdio.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c
> index eb344f6d4a7b..e584abda585b 100644
> --- a/drivers/net/mdio/fwnode_mdio.c
> +++ b/drivers/net/mdio/fwnode_mdio.c
> @@ -97,10 +97,8 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,
>  	 * register it
>  	 */
>  	rc = phy_device_register(phy);
> -	if (rc) {
> -		fwnode_handle_put(child);
> +	if (rc)
>  		return rc;
> -	}

The current code is:

        /* Associate the fwnode with the device structure so it
         * can be looked up later
         */
        fwnode_handle_get(child);
        device_set_node(&phy->mdio.dev, child);

        /* All data is now stored in the phy struct;
         * register it
         */
        rc = phy_device_register(phy);
        if (rc) {
                fwnode_handle_put(child);
                return rc;
        }

The fwnode_handle_put(child) balances the earlier
fwnode_handle_get(child).

The code will look wrong without this balance. Please find a better
fix which actually looks correct.

    Andrew

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-01  2:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-30  9:17 [PATCH net] net: mdiobus: remove unneccessary fwnode_handle_put() in the error path Yang Yingliang
2022-12-01  2:41 ` Andrew Lunn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.