linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v3] net: fec: fix clock count mis-match
@ 2019-11-18 12:18 Chuhong Yuan
  2019-11-19  1:49 ` [EXT] " Andy Duan
  2019-11-19 22:55 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Chuhong Yuan @ 2019-11-18 12:18 UTC (permalink / raw)
  Cc: Fugang Duan, David S . Miller, netdev, linux-kernel, Chuhong Yuan

pm_runtime_put_autosuspend in probe will call suspend to disable clks
automatically if CONFIG_PM is defined. (If CONFIG_PM is not defined,
its implementation will be empty, then suspend will not be called.)

Therefore, we can call pm_runtime_get_sync to resume it first to enable
clks, which matches the suspend. (Only when CONFIG_PM is defined, otherwise
pm_runtime_get_sync will also be empty, then resume will not be called.)

Then it is fine to disable clks without causing clock count mis-match.

Fixes: c43eab3eddb4 ("net: fec: add missed clk_disable_unprepare in remove")
Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
 drivers/net/ethernet/freescale/fec_main.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index a9c386b63581..4bb30761abfc 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -3636,6 +3636,11 @@ fec_drv_remove(struct platform_device *pdev)
 	struct net_device *ndev = platform_get_drvdata(pdev);
 	struct fec_enet_private *fep = netdev_priv(ndev);
 	struct device_node *np = pdev->dev.of_node;
+	int ret;
+
+	ret = pm_runtime_get_sync(&pdev->dev);
+	if (ret < 0)
+		return ret;
 
 	cancel_work_sync(&fep->tx_timeout_work);
 	fec_ptp_stop(pdev);
@@ -3643,15 +3648,17 @@ fec_drv_remove(struct platform_device *pdev)
 	fec_enet_mii_remove(fep);
 	if (fep->reg_phy)
 		regulator_disable(fep->reg_phy);
-	pm_runtime_put(&pdev->dev);
-	pm_runtime_disable(&pdev->dev);
-	clk_disable_unprepare(fep->clk_ahb);
-	clk_disable_unprepare(fep->clk_ipg);
+
 	if (of_phy_is_fixed_link(np))
 		of_phy_deregister_fixed_link(np);
 	of_node_put(fep->phy_node);
 	free_netdev(ndev);
 
+	clk_disable_unprepare(fep->clk_ahb);
+	clk_disable_unprepare(fep->clk_ipg);
+	pm_runtime_put_noidle(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+
 	return 0;
 }
 
-- 
2.24.0


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

* RE: [EXT] [PATCH net v3] net: fec: fix clock count mis-match
  2019-11-18 12:18 [PATCH net v3] net: fec: fix clock count mis-match Chuhong Yuan
@ 2019-11-19  1:49 ` Andy Duan
  2019-11-19 22:55 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Duan @ 2019-11-19  1:49 UTC (permalink / raw)
  To: Chuhong Yuan; +Cc: David S . Miller, netdev, linux-kernel

From: Chuhong Yuan <hslester96@gmail.com> Sent: Monday, November 18, 2019 8:18 PM
> pm_runtime_put_autosuspend in probe will call suspend to disable clks
> automatically if CONFIG_PM is defined. (If CONFIG_PM is not defined, its
> implementation will be empty, then suspend will not be called.)

suspend -> runtime suspend
> 
> Therefore, we can call pm_runtime_get_sync to resume it first to enable clks,
resume -> runtime resume
> which matches the suspend. (Only when CONFIG_PM is defined, otherwise
suspend -> runtime suspend
> pm_runtime_get_sync will also be empty, then resume will not be called.)
> 
> Then it is fine to disable clks without causing clock count mis-match.
> 
> Fixes: c43eab3eddb4 ("net: fec: add missed clk_disable_unprepare in
> remove")
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
>  drivers/net/ethernet/freescale/fec_main.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/freescale/fec_main.c
> b/drivers/net/ethernet/freescale/fec_main.c
> index a9c386b63581..4bb30761abfc 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -3636,6 +3636,11 @@ fec_drv_remove(struct platform_device *pdev)
>         struct net_device *ndev = platform_get_drvdata(pdev);
>         struct fec_enet_private *fep = netdev_priv(ndev);
>         struct device_node *np = pdev->dev.of_node;
> +       int ret;
> +
> +       ret = pm_runtime_get_sync(&pdev->dev);
> +       if (ret < 0)
> +               return ret;
> 
>         cancel_work_sync(&fep->tx_timeout_work);
>         fec_ptp_stop(pdev);
> @@ -3643,15 +3648,17 @@ fec_drv_remove(struct platform_device *pdev)
>         fec_enet_mii_remove(fep);
>         if (fep->reg_phy)
>                 regulator_disable(fep->reg_phy);
> -       pm_runtime_put(&pdev->dev);
> -       pm_runtime_disable(&pdev->dev);
> -       clk_disable_unprepare(fep->clk_ahb);
> -       clk_disable_unprepare(fep->clk_ipg);
> +
>         if (of_phy_is_fixed_link(np))
>                 of_phy_deregister_fixed_link(np);
>         of_node_put(fep->phy_node);
>         free_netdev(ndev);
> 
> +       clk_disable_unprepare(fep->clk_ahb);
> +       clk_disable_unprepare(fep->clk_ipg);
> +       pm_runtime_put_noidle(&pdev->dev);
> +       pm_runtime_disable(&pdev->dev);
> +
>         return 0;
>  }
> 
> --
> 2.24.0


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

* Re: [PATCH net v3] net: fec: fix clock count mis-match
  2019-11-18 12:18 [PATCH net v3] net: fec: fix clock count mis-match Chuhong Yuan
  2019-11-19  1:49 ` [EXT] " Andy Duan
@ 2019-11-19 22:55 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-11-19 22:55 UTC (permalink / raw)
  To: hslester96; +Cc: fugang.duan, netdev, linux-kernel

From: Chuhong Yuan <hslester96@gmail.com>
Date: Mon, 18 Nov 2019 20:18:26 +0800

> pm_runtime_put_autosuspend in probe will call suspend to disable clks
> automatically if CONFIG_PM is defined. (If CONFIG_PM is not defined,
> its implementation will be empty, then suspend will not be called.)
> 
> Therefore, we can call pm_runtime_get_sync to resume it first to enable
> clks, which matches the suspend. (Only when CONFIG_PM is defined, otherwise
> pm_runtime_get_sync will also be empty, then resume will not be called.)
> 
> Then it is fine to disable clks without causing clock count mis-match.
> 
> Fixes: c43eab3eddb4 ("net: fec: add missed clk_disable_unprepare in remove")
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>

Please fix the commit message typos pointed out by Andy Duan and resubmit,
thank you.

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

end of thread, other threads:[~2019-11-19 22:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-18 12:18 [PATCH net v3] net: fec: fix clock count mis-match Chuhong Yuan
2019-11-19  1:49 ` [EXT] " Andy Duan
2019-11-19 22:55 ` David Miller

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).