linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm
@ 2017-01-02 11:56 Johan Hovold
  2017-01-02 11:56 ` [PATCH net 1/3] net: stmmac: dwmac-oxnas: fix of-node leak Johan Hovold
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Johan Hovold @ 2017-01-02 11:56 UTC (permalink / raw)
  To: David S. Miller
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Neil Armstrong, netdev,
	linux-oxnas, linux-kernel, Johan Hovold

These patches fixes of-node and fixed-phydev leaks in the recently added
dwmac-oxnas driver, and ultimately switches over to using the generic pm
implementation as the required callbacks are now in place.

Note that this series has only been compile tested.

Johan


Johan Hovold (3):
  net: stmmac: dwmac-oxnas: fix of-node leak
  net: stmmac: dwmac-oxnas: fix fixed-link-phydev leaks
  net: stmmac: dwmac-oxnas: use generic pm implementation

 drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c | 89 +++++++++--------------
 1 file changed, 33 insertions(+), 56 deletions(-)

-- 
2.10.2

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

* [PATCH net 1/3] net: stmmac: dwmac-oxnas: fix of-node leak
  2017-01-02 11:56 [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm Johan Hovold
@ 2017-01-02 11:56 ` Johan Hovold
  2017-01-02 11:56 ` [PATCH net 2/3] net: stmmac: dwmac-oxnas: fix fixed-link-phydev leaks Johan Hovold
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2017-01-02 11:56 UTC (permalink / raw)
  To: David S. Miller
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Neil Armstrong, netdev,
	linux-oxnas, linux-kernel, Johan Hovold

Use the syscon lookup-by-phandle helper so that the reference taken by
of_parse_phandle() is released when done with the node.

Fixes: 5ed7414062e7 ("net: stmmac: Add OXNAS Glue Driver")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
index c35597586121..fcc237e0aae1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
@@ -109,16 +109,9 @@ static int oxnas_dwmac_probe(struct platform_device *pdev)
 {
 	struct plat_stmmacenet_data *plat_dat;
 	struct stmmac_resources stmmac_res;
-	struct device_node *sysctrl;
 	struct oxnas_dwmac *dwmac;
 	int ret;
 
-	sysctrl = of_parse_phandle(pdev->dev.of_node, "oxsemi,sys-ctrl", 0);
-	if (!sysctrl) {
-		dev_err(&pdev->dev, "failed to get sys-ctrl node\n");
-		return -EINVAL;
-	}
-
 	ret = stmmac_get_platform_resources(pdev, &stmmac_res);
 	if (ret)
 		return ret;
@@ -134,7 +127,8 @@ static int oxnas_dwmac_probe(struct platform_device *pdev)
 	dwmac->dev = &pdev->dev;
 	plat_dat->bsp_priv = dwmac;
 
-	dwmac->regmap = syscon_node_to_regmap(sysctrl);
+	dwmac->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
+							"oxsemi,sys-ctrl");
 	if (IS_ERR(dwmac->regmap)) {
 		dev_err(&pdev->dev, "failed to have sysctrl regmap\n");
 		return PTR_ERR(dwmac->regmap);
-- 
2.10.2

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

* [PATCH net 2/3] net: stmmac: dwmac-oxnas: fix fixed-link-phydev leaks
  2017-01-02 11:56 [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm Johan Hovold
  2017-01-02 11:56 ` [PATCH net 1/3] net: stmmac: dwmac-oxnas: fix of-node leak Johan Hovold
@ 2017-01-02 11:56 ` Johan Hovold
  2017-01-02 11:56 ` [PATCH net 3/3] net: stmmac: dwmac-oxnas: use generic pm implementation Johan Hovold
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2017-01-02 11:56 UTC (permalink / raw)
  To: David S. Miller
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Neil Armstrong, netdev,
	linux-oxnas, linux-kernel, Johan Hovold

Make sure to deregister and free any fixed-link phy registered during
probe on probe errors and on driver unbind by calling the new glue
helper function.

For driver unbind, use the generic stmmac-platform remove implementation
and add an exit callback to disable the clock.

Fixes: 5ed7414062e7 ("net: stmmac: Add OXNAS Glue Driver")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c | 41 ++++++++++++++---------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
index fcc237e0aae1..3efd110613df 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
@@ -105,6 +105,13 @@ static int oxnas_dwmac_init(struct oxnas_dwmac *dwmac)
 	return 0;
 }
 
+static void oxnas_dwmac_exit(struct platform_device *pdev, void *priv)
+{
+	struct oxnas_dwmac *dwmac = priv;
+
+	clk_disable_unprepare(dwmac->clk);
+}
+
 static int oxnas_dwmac_probe(struct platform_device *pdev)
 {
 	struct plat_stmmacenet_data *plat_dat;
@@ -121,40 +128,44 @@ static int oxnas_dwmac_probe(struct platform_device *pdev)
 		return PTR_ERR(plat_dat);
 
 	dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
-	if (!dwmac)
-		return -ENOMEM;
+	if (!dwmac) {
+		ret = -ENOMEM;
+		goto err_remove_config_dt;
+	}
 
 	dwmac->dev = &pdev->dev;
 	plat_dat->bsp_priv = dwmac;
+	plat_dat->exit = oxnas_dwmac_exit;
 
 	dwmac->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
 							"oxsemi,sys-ctrl");
 	if (IS_ERR(dwmac->regmap)) {
 		dev_err(&pdev->dev, "failed to have sysctrl regmap\n");
-		return PTR_ERR(dwmac->regmap);
+		ret = PTR_ERR(dwmac->regmap);
+		goto err_remove_config_dt;
 	}
 
 	dwmac->clk = devm_clk_get(&pdev->dev, "gmac");
-	if (IS_ERR(dwmac->clk))
-		return PTR_ERR(dwmac->clk);
+	if (IS_ERR(dwmac->clk)) {
+		ret = PTR_ERR(dwmac->clk);
+		goto err_remove_config_dt;
+	}
 
 	ret = oxnas_dwmac_init(dwmac);
 	if (ret)
-		return ret;
+		goto err_remove_config_dt;
 
 	ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
 	if (ret)
-		clk_disable_unprepare(dwmac->clk);
+		goto err_dwmac_exit;
 
-	return ret;
-}
 
-static int oxnas_dwmac_remove(struct platform_device *pdev)
-{
-	struct oxnas_dwmac *dwmac = get_stmmac_bsp_priv(&pdev->dev);
-	int ret = stmmac_dvr_remove(&pdev->dev);
+	return 0;
 
-	clk_disable_unprepare(dwmac->clk);
+err_dwmac_exit:
+	oxnas_dwmac_exit(pdev, plat_dat->bsp_priv);
+err_remove_config_dt:
+	stmmac_remove_config_dt(pdev, plat_dat);
 
 	return ret;
 }
@@ -197,7 +208,7 @@ MODULE_DEVICE_TABLE(of, oxnas_dwmac_match);
 
 static struct platform_driver oxnas_dwmac_driver = {
 	.probe  = oxnas_dwmac_probe,
-	.remove = oxnas_dwmac_remove,
+	.remove = stmmac_pltfr_remove,
 	.driver = {
 		.name           = "oxnas-dwmac",
 		.pm		= &oxnas_dwmac_pm_ops,
-- 
2.10.2

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

* [PATCH net 3/3] net: stmmac: dwmac-oxnas: use generic pm implementation
  2017-01-02 11:56 [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm Johan Hovold
  2017-01-02 11:56 ` [PATCH net 1/3] net: stmmac: dwmac-oxnas: fix of-node leak Johan Hovold
  2017-01-02 11:56 ` [PATCH net 2/3] net: stmmac: dwmac-oxnas: fix fixed-link-phydev leaks Johan Hovold
@ 2017-01-02 11:56 ` Johan Hovold
  2017-01-02 15:03 ` [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm Neil Armstrong
  2017-01-03 14:33 ` David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2017-01-02 11:56 UTC (permalink / raw)
  To: David S. Miller
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Neil Armstrong, netdev,
	linux-oxnas, linux-kernel, Johan Hovold

Now that we have an exit callback in place, add init as well and get rid
of the custom PM callbacks in favour of the generic ones.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c | 38 +++--------------------
 1 file changed, 5 insertions(+), 33 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
index 3efd110613df..3dc7d279f805 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c
@@ -60,8 +60,9 @@ struct oxnas_dwmac {
 	struct regmap	*regmap;
 };
 
-static int oxnas_dwmac_init(struct oxnas_dwmac *dwmac)
+static int oxnas_dwmac_init(struct platform_device *pdev, void *priv)
 {
+	struct oxnas_dwmac *dwmac = priv;
 	unsigned int value;
 	int ret;
 
@@ -135,6 +136,7 @@ static int oxnas_dwmac_probe(struct platform_device *pdev)
 
 	dwmac->dev = &pdev->dev;
 	plat_dat->bsp_priv = dwmac;
+	plat_dat->init = oxnas_dwmac_init;
 	plat_dat->exit = oxnas_dwmac_exit;
 
 	dwmac->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
@@ -151,7 +153,7 @@ static int oxnas_dwmac_probe(struct platform_device *pdev)
 		goto err_remove_config_dt;
 	}
 
-	ret = oxnas_dwmac_init(dwmac);
+	ret = oxnas_dwmac_init(pdev, plat_dat->bsp_priv);
 	if (ret)
 		goto err_remove_config_dt;
 
@@ -170,36 +172,6 @@ static int oxnas_dwmac_probe(struct platform_device *pdev)
 	return ret;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int oxnas_dwmac_suspend(struct device *dev)
-{
-	struct oxnas_dwmac *dwmac = get_stmmac_bsp_priv(dev);
-	int ret;
-
-	ret = stmmac_suspend(dev);
-	clk_disable_unprepare(dwmac->clk);
-
-	return ret;
-}
-
-static int oxnas_dwmac_resume(struct device *dev)
-{
-	struct oxnas_dwmac *dwmac = get_stmmac_bsp_priv(dev);
-	int ret;
-
-	ret = oxnas_dwmac_init(dwmac);
-	if (ret)
-		return ret;
-
-	ret = stmmac_resume(dev);
-
-	return ret;
-}
-#endif /* CONFIG_PM_SLEEP */
-
-static SIMPLE_DEV_PM_OPS(oxnas_dwmac_pm_ops,
-	oxnas_dwmac_suspend, oxnas_dwmac_resume);
-
 static const struct of_device_id oxnas_dwmac_match[] = {
 	{ .compatible = "oxsemi,ox820-dwmac" },
 	{ }
@@ -211,7 +183,7 @@ static struct platform_driver oxnas_dwmac_driver = {
 	.remove = stmmac_pltfr_remove,
 	.driver = {
 		.name           = "oxnas-dwmac",
-		.pm		= &oxnas_dwmac_pm_ops,
+		.pm		= &stmmac_pltfr_pm_ops,
 		.of_match_table = oxnas_dwmac_match,
 	},
 };
-- 
2.10.2

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

* Re: [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm
  2017-01-02 11:56 [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm Johan Hovold
                   ` (2 preceding siblings ...)
  2017-01-02 11:56 ` [PATCH net 3/3] net: stmmac: dwmac-oxnas: use generic pm implementation Johan Hovold
@ 2017-01-02 15:03 ` Neil Armstrong
  2017-01-03 14:33 ` David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Neil Armstrong @ 2017-01-02 15:03 UTC (permalink / raw)
  To: Johan Hovold, David S. Miller
  Cc: Giuseppe Cavallaro, Alexandre Torgue, netdev, linux-oxnas, linux-kernel

On 01/02/2017 12:56 PM, Johan Hovold wrote:
> These patches fixes of-node and fixed-phydev leaks in the recently added
> dwmac-oxnas driver, and ultimately switches over to using the generic pm
> implementation as the required callbacks are now in place.
> 
> Note that this series has only been compile tested.
> 
> Johan
> 
> 
> Johan Hovold (3):
>   net: stmmac: dwmac-oxnas: fix of-node leak
>   net: stmmac: dwmac-oxnas: fix fixed-link-phydev leaks
>   net: stmmac: dwmac-oxnas: use generic pm implementation
> 
>  drivers/net/ethernet/stmicro/stmmac/dwmac-oxnas.c | 89 +++++++++--------------
>  1 file changed, 33 insertions(+), 56 deletions(-)
> 

Hi Johan,

This series looks good, I will (hopefully) send a Tested-by in the next few days.

Thanks,
Neil

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

* Re: [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm
  2017-01-02 11:56 [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm Johan Hovold
                   ` (3 preceding siblings ...)
  2017-01-02 15:03 ` [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm Neil Armstrong
@ 2017-01-03 14:33 ` David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2017-01-03 14:33 UTC (permalink / raw)
  To: johan
  Cc: peppe.cavallaro, alexandre.torgue, narmstrong, netdev,
	linux-oxnas, linux-kernel

From: Johan Hovold <johan@kernel.org>
Date: Mon,  2 Jan 2017 12:56:01 +0100

> These patches fixes of-node and fixed-phydev leaks in the recently added
> dwmac-oxnas driver, and ultimately switches over to using the generic pm
> implementation as the required callbacks are now in place.

Series applied.

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

end of thread, other threads:[~2017-01-03 14:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-02 11:56 [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm Johan Hovold
2017-01-02 11:56 ` [PATCH net 1/3] net: stmmac: dwmac-oxnas: fix of-node leak Johan Hovold
2017-01-02 11:56 ` [PATCH net 2/3] net: stmmac: dwmac-oxnas: fix fixed-link-phydev leaks Johan Hovold
2017-01-02 11:56 ` [PATCH net 3/3] net: stmmac: dwmac-oxnas: use generic pm implementation Johan Hovold
2017-01-02 15:03 ` [PATCH net 0/3] net: stmmac: dwmac-oxnas: fix leaks and simplify pm Neil Armstrong
2017-01-03 14:33 ` 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).