[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Y4gUQC+Gh4b/lr5f@lunn.ch>
Date: Thu, 1 Dec 2022 03:41:04 +0100
From: Andrew Lunn <andrew@...n.ch>
To: Yang Yingliang <yangyingliang@...wei.com>
Cc: netdev@...r.kernel.org, hkallweit1@...il.com,
linux@...linux.org.uk, davem@...emloft.net, edumazet@...gle.com,
kuba@...nel.org, pabeni@...hat.com, ioana.ciornei@....com,
calvin.johnson@....nxp.com, grant.likely@....com,
zengheng4@...wei.com
Subject: Re: [PATCH net] net: mdiobus: remove unneccessary
fwnode_handle_put() in the error path
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@...wei.com>
> Tested-by: Zeng Heng <zengheng4@...wei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@...wei.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
Powered by blists - more mailing lists