linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: hns: Fix missing put_device() call in hns_mac_register_phy
@ 2022-01-10  6:40 Miaoqian Lin
  2022-01-12  4:33 ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Miaoqian Lin @ 2022-01-10  6:40 UTC (permalink / raw)
  Cc: linmq006, Yisen Zhuang, Salil Mehta, David S. Miller,
	Jakub Kicinski, Yang Shen, Yonglong Liu, Peng Li,
	Matthias Brugger, netdev, linux-kernel

We need to drop the reference taken by hns_dsaf_find_platform_device
Missing put_device() may cause refcount leak.

Fixes: 804ffe5c6197 ("net: hns: support deferred probe when no mdio")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 7edf8569514c..7364e05487c7 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -764,6 +764,7 @@ static int hns_mac_register_phy(struct hns_mac_cb *mac_cb)
 		dev_err(mac_cb->dev,
 			"mac%d mdio is NULL, dsaf will probe again later\n",
 			mac_cb->mac_id);
+		put_device(&pdev->dev);
 		return -EPROBE_DEFER;
 	}
 
-- 
2.17.1


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

* Re: [PATCH] net: hns: Fix missing put_device() call in hns_mac_register_phy
  2022-01-10  6:40 [PATCH] net: hns: Fix missing put_device() call in hns_mac_register_phy Miaoqian Lin
@ 2022-01-12  4:33 ` Jakub Kicinski
  2022-01-12 10:39   ` [PATCH v2] " Miaoqian Lin
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2022-01-12  4:33 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Yisen Zhuang, Salil Mehta, David S. Miller, Yang Shen,
	Yonglong Liu, Peng Li, Matthias Brugger, netdev, linux-kernel

On Mon, 10 Jan 2022 06:40:29 +0000 Miaoqian Lin wrote:
> We need to drop the reference taken by hns_dsaf_find_platform_device
> Missing put_device() may cause refcount leak.
> 
> Fixes: 804ffe5c6197 ("net: hns: support deferred probe when no mdio")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
> index 7edf8569514c..7364e05487c7 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
> @@ -764,6 +764,7 @@ static int hns_mac_register_phy(struct hns_mac_cb *mac_cb)
>  		dev_err(mac_cb->dev,
>  			"mac%d mdio is NULL, dsaf will probe again later\n",
>  			mac_cb->mac_id);
> +		put_device(&pdev->dev);
>  		return -EPROBE_DEFER;
>  	}
>  

With more context:

@@ -755,24 +755,25 @@ static int hns_mac_register_phy(struct hns_mac_cb *mac_cb)
        pdev = hns_dsaf_find_platform_device(args.fwnode);
        if (!pdev) {
                dev_err(mac_cb->dev, "mac%d mdio pdev is NULL\n",
                        mac_cb->mac_id);
                return  -EINVAL;
        }
 
        mii_bus = platform_get_drvdata(pdev);
        if (!mii_bus) {
                dev_err(mac_cb->dev,
                        "mac%d mdio is NULL, dsaf will probe again later\n",
                        mac_cb->mac_id);
+               put_device(&pdev->dev);
                return -EPROBE_DEFER;
        }
 
        rc = hns_mac_register_phydev(mii_bus, mac_cb, addr);
        if (!rc)
                dev_dbg(mac_cb->dev, "mac%d register phy addr:%d\n",
                        mac_cb->mac_id, addr);
 
        return rc;
 }

Looks like if put_device() is missing it will also be missing in case
hns_mac_register_phydev() returns an error.

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

* [PATCH v2] net: hns: Fix missing put_device() call in hns_mac_register_phy
  2022-01-12  4:33 ` Jakub Kicinski
@ 2022-01-12 10:39   ` Miaoqian Lin
  2022-01-12 13:46     ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Miaoqian Lin @ 2022-01-12 10:39 UTC (permalink / raw)
  To: kuba
  Cc: davem, linmq006, linux-kernel, lipeng321, liuyonglong, mbrugger,
	netdev, salil.mehta, shenyang39, yisen.zhuang

We need to drop the reference taken by hns_dsaf_find_platform_device
Missing put_device() may cause refcount leak.

Fixes: 804ffe5c6197 ("net: hns: support deferred probe when no mdio")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
Changes in v2:
- add put_device when hns_mac_register_phydev fails.
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 7edf8569514c..cba9d92e057e 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -764,13 +764,16 @@ static int hns_mac_register_phy(struct hns_mac_cb *mac_cb)
 		dev_err(mac_cb->dev,
 			"mac%d mdio is NULL, dsaf will probe again later\n",
 			mac_cb->mac_id);
+		put_device(&pdev->dev);
 		return -EPROBE_DEFER;
 	}
 
 	rc = hns_mac_register_phydev(mii_bus, mac_cb, addr);
-	if (!rc)
+	if (!rc) {
 		dev_dbg(mac_cb->dev, "mac%d register phy addr:%d\n",
 			mac_cb->mac_id, addr);
+		put_device(&pdev->dev);
+	}
 
 	return rc;
 }
-- 
2.17.1


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

* Re: [PATCH v2] net: hns: Fix missing put_device() call in hns_mac_register_phy
  2022-01-12 10:39   ` [PATCH v2] " Miaoqian Lin
@ 2022-01-12 13:46     ` Andrew Lunn
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2022-01-12 13:46 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: kuba, davem, linux-kernel, lipeng321, liuyonglong, mbrugger,
	netdev, salil.mehta, shenyang39, yisen.zhuang

On Wed, Jan 12, 2022 at 10:39:19AM +0000, Miaoqian Lin wrote:
> We need to drop the reference taken by hns_dsaf_find_platform_device
> Missing put_device() may cause refcount leak.

Is the put also missing on driver unload?

As a fix for net, it might be better to rename
dsaf_find_platform_device() to dsaf_get_platform_device() and add a
dsaf_put_platform_device(). Add similar undo functions where ever
needed, and make sure they get called.

	Andrew

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-10  6:40 [PATCH] net: hns: Fix missing put_device() call in hns_mac_register_phy Miaoqian Lin
2022-01-12  4:33 ` Jakub Kicinski
2022-01-12 10:39   ` [PATCH v2] " Miaoqian Lin
2022-01-12 13:46     ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).