diff mbox

[-next] net: phy: Add missing of_node_put() in xgmiitorgmii_probe()

Message ID 1471706815-27723-1-git-send-email-weiyj.lk@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Yongjun Aug. 20, 2016, 3:26 p.m. UTC
This node pointer is returned by of_parse_phandle() with
refcount incremented in this function. of_node_put() on it
before exitting this function.

This is detected by Coccinelle semantic patch.

Signed-off-by: Wei Yongjun <weiyj.lk@gmail.com>
---
 drivers/net/phy/xilinx_gmii2rgmii.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Andrew Lunn Aug. 20, 2016, 5:36 p.m. UTC | #1
On Sat, Aug 20, 2016 at 03:26:55PM +0000, Wei Yongjun wrote:
> This node pointer is returned by of_parse_phandle() with
> refcount incremented in this function. of_node_put() on it
> before exitting this function.

Hi Wei

You are only releasing on the error path. What about the successful
path?

	Andrew

> 
> This is detected by Coccinelle semantic patch.
> 
> Signed-off-by: Wei Yongjun <weiyj.lk@gmail.com>
> ---
>  drivers/net/phy/xilinx_gmii2rgmii.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c
> index cad6e19..4f05e5e 100644
> --- a/drivers/net/phy/xilinx_gmii2rgmii.c
> +++ b/drivers/net/phy/xilinx_gmii2rgmii.c
> @@ -75,6 +75,7 @@ int xgmiitorgmii_probe(struct mdio_device *mdiodev)
>  	priv->phy_dev = of_phy_find_device(phy_node);
>  	if (!priv->phy_dev) {
>  		dev_info(dev, "Couldn't find phydev\n");
> +		of_node_put(phy_node);
>  		return -EPROBE_DEFER;
>  	}
>
David Miller Aug. 21, 2016, 10:29 p.m. UTC | #2
From: Andrew Lunn <andrew@lunn.ch>
Date: Sat, 20 Aug 2016 19:36:05 +0200

> On Sat, Aug 20, 2016 at 03:26:55PM +0000, Wei Yongjun wrote:
>> This node pointer is returned by of_parse_phandle() with
>> refcount incremented in this function. of_node_put() on it
>> before exitting this function.
> 
> Hi Wei
> 
> You are only releasing on the error path. What about the successful
> path?

Agreed, as far as I can tell we do need to release it unconditionally
here.
diff mbox

Patch

diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c
index cad6e19..4f05e5e 100644
--- a/drivers/net/phy/xilinx_gmii2rgmii.c
+++ b/drivers/net/phy/xilinx_gmii2rgmii.c
@@ -75,6 +75,7 @@  int xgmiitorgmii_probe(struct mdio_device *mdiodev)
 	priv->phy_dev = of_phy_find_device(phy_node);
 	if (!priv->phy_dev) {
 		dev_info(dev, "Couldn't find phydev\n");
+		of_node_put(phy_node);
 		return -EPROBE_DEFER;
 	}