aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/ti
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2016-11-17 11:40:00 -0500
committerDavid S. Miller <davem@davemloft.net>2016-11-18 13:48:53 -0500
commita4e32b0d0a26ba2f2ba1c65bd403d06ccc1df29c (patch)
tree8cb911578d56f340e4e4fb4912bf96e111e43af2 /drivers/net/ethernet/ti
parent86e1d5adcef961eb383ce4eacbe0ef22f06e2045 (diff)
net: ethernet: ti: cpsw: fix deferred probe
Make sure to deregister all child devices also on probe errors to avoid leaks and to fix probe deferral: cpsw 4a100000.ethernet: omap_device: omap_device_enable() called from invalid state 1 cpsw 4a100000.ethernet: use pm_runtime_put_sync_suspend() in driver? cpsw: probe of 4a100000.ethernet failed with error -22 Add generic helper to undo the effects of cpsw_probe_dt(), which will also be used in a follow-on patch to fix further leaks that have been introduced more recently. Note that the platform device is now runtime-resumed before registering any child devices in order to make sure that it is synchronously suspended after having deregistered the children in the error path. Fixes: 1fb19aa730e4 ("net: cpsw: Add parent<->child relation support between cpsw and mdio") Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/ti')
-rw-r--r--drivers/net/ethernet/ti/cpsw.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 84c5d214557e..5d14abb06486 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -2441,6 +2441,11 @@ no_phy_slave:
2441 return 0; 2441 return 0;
2442} 2442}
2443 2443
2444static void cpsw_remove_dt(struct platform_device *pdev)
2445{
2446 of_platform_depopulate(&pdev->dev);
2447}
2448
2444static int cpsw_probe_dual_emac(struct cpsw_priv *priv) 2449static int cpsw_probe_dual_emac(struct cpsw_priv *priv)
2445{ 2450{
2446 struct cpsw_common *cpsw = priv->cpsw; 2451 struct cpsw_common *cpsw = priv->cpsw;
@@ -2585,10 +2590,19 @@ static int cpsw_probe(struct platform_device *pdev)
2585 /* Select default pin state */ 2590 /* Select default pin state */
2586 pinctrl_pm_select_default_state(&pdev->dev); 2591 pinctrl_pm_select_default_state(&pdev->dev);
2587 2592
2593 /* Need to enable clocks with runtime PM api to access module
2594 * registers
2595 */
2596 ret = pm_runtime_get_sync(&pdev->dev);
2597 if (ret < 0) {
2598 pm_runtime_put_noidle(&pdev->dev);
2599 goto clean_runtime_disable_ret;
2600 }
2601
2588 if (cpsw_probe_dt(&cpsw->data, pdev)) { 2602 if (cpsw_probe_dt(&cpsw->data, pdev)) {
2589 dev_err(&pdev->dev, "cpsw: platform data missing\n"); 2603 dev_err(&pdev->dev, "cpsw: platform data missing\n");
2590 ret = -ENODEV; 2604 ret = -ENODEV;
2591 goto clean_runtime_disable_ret; 2605 goto clean_dt_ret;
2592 } 2606 }
2593 data = &cpsw->data; 2607 data = &cpsw->data;
2594 cpsw->rx_ch_num = 1; 2608 cpsw->rx_ch_num = 1;
@@ -2609,7 +2623,7 @@ static int cpsw_probe(struct platform_device *pdev)
2609 GFP_KERNEL); 2623 GFP_KERNEL);
2610 if (!cpsw->slaves) { 2624 if (!cpsw->slaves) {
2611 ret = -ENOMEM; 2625 ret = -ENOMEM;
2612 goto clean_runtime_disable_ret; 2626 goto clean_dt_ret;
2613 } 2627 }
2614 for (i = 0; i < data->slaves; i++) 2628 for (i = 0; i < data->slaves; i++)
2615 cpsw->slaves[i].slave_num = i; 2629 cpsw->slaves[i].slave_num = i;
@@ -2621,7 +2635,7 @@ static int cpsw_probe(struct platform_device *pdev)
2621 if (IS_ERR(clk)) { 2635 if (IS_ERR(clk)) {
2622 dev_err(priv->dev, "fck is not found\n"); 2636 dev_err(priv->dev, "fck is not found\n");
2623 ret = -ENODEV; 2637 ret = -ENODEV;
2624 goto clean_runtime_disable_ret; 2638 goto clean_dt_ret;
2625 } 2639 }
2626 cpsw->bus_freq_mhz = clk_get_rate(clk) / 1000000; 2640 cpsw->bus_freq_mhz = clk_get_rate(clk) / 1000000;
2627 2641
@@ -2629,25 +2643,17 @@ static int cpsw_probe(struct platform_device *pdev)
2629 ss_regs = devm_ioremap_resource(&pdev->dev, ss_res); 2643 ss_regs = devm_ioremap_resource(&pdev->dev, ss_res);
2630 if (IS_ERR(ss_regs)) { 2644 if (IS_ERR(ss_regs)) {
2631 ret = PTR_ERR(ss_regs); 2645 ret = PTR_ERR(ss_regs);
2632 goto clean_runtime_disable_ret; 2646 goto clean_dt_ret;
2633 } 2647 }
2634 cpsw->regs = ss_regs; 2648 cpsw->regs = ss_regs;
2635 2649
2636 /* Need to enable clocks with runtime PM api to access module
2637 * registers
2638 */
2639 ret = pm_runtime_get_sync(&pdev->dev);
2640 if (ret < 0) {
2641 pm_runtime_put_noidle(&pdev->dev);
2642 goto clean_runtime_disable_ret;
2643 }
2644 cpsw->version = readl(&cpsw->regs->id_ver); 2650 cpsw->version = readl(&cpsw->regs->id_ver);
2645 2651
2646 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 2652 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2647 cpsw->wr_regs = devm_ioremap_resource(&pdev->dev, res); 2653 cpsw->wr_regs = devm_ioremap_resource(&pdev->dev, res);
2648 if (IS_ERR(cpsw->wr_regs)) { 2654 if (IS_ERR(cpsw->wr_regs)) {
2649 ret = PTR_ERR(cpsw->wr_regs); 2655 ret = PTR_ERR(cpsw->wr_regs);
2650 goto clean_pm_runtime_put_ret; 2656 goto clean_dt_ret;
2651 } 2657 }
2652 2658
2653 memset(&dma_params, 0, sizeof(dma_params)); 2659 memset(&dma_params, 0, sizeof(dma_params));
@@ -2684,7 +2690,7 @@ static int cpsw_probe(struct platform_device *pdev)
2684 default: 2690 default:
2685 dev_err(priv->dev, "unknown version 0x%08x\n", cpsw->version); 2691 dev_err(priv->dev, "unknown version 0x%08x\n", cpsw->version);
2686 ret = -ENODEV; 2692 ret = -ENODEV;
2687 goto clean_pm_runtime_put_ret; 2693 goto clean_dt_ret;
2688 } 2694 }
2689 for (i = 0; i < cpsw->data.slaves; i++) { 2695 for (i = 0; i < cpsw->data.slaves; i++) {
2690 struct cpsw_slave *slave = &cpsw->slaves[i]; 2696 struct cpsw_slave *slave = &cpsw->slaves[i];
@@ -2713,7 +2719,7 @@ static int cpsw_probe(struct platform_device *pdev)
2713 if (!cpsw->dma) { 2719 if (!cpsw->dma) {
2714 dev_err(priv->dev, "error initializing dma\n"); 2720 dev_err(priv->dev, "error initializing dma\n");
2715 ret = -ENOMEM; 2721 ret = -ENOMEM;
2716 goto clean_pm_runtime_put_ret; 2722 goto clean_dt_ret;
2717 } 2723 }
2718 2724
2719 cpsw->txch[0] = cpdma_chan_create(cpsw->dma, 0, cpsw_tx_handler, 0); 2725 cpsw->txch[0] = cpdma_chan_create(cpsw->dma, 0, cpsw_tx_handler, 0);
@@ -2823,7 +2829,8 @@ clean_ale_ret:
2823 cpsw_ale_destroy(cpsw->ale); 2829 cpsw_ale_destroy(cpsw->ale);
2824clean_dma_ret: 2830clean_dma_ret:
2825 cpdma_ctlr_destroy(cpsw->dma); 2831 cpdma_ctlr_destroy(cpsw->dma);
2826clean_pm_runtime_put_ret: 2832clean_dt_ret:
2833 cpsw_remove_dt(pdev);
2827 pm_runtime_put_sync(&pdev->dev); 2834 pm_runtime_put_sync(&pdev->dev);
2828clean_runtime_disable_ret: 2835clean_runtime_disable_ret:
2829 pm_runtime_disable(&pdev->dev); 2836 pm_runtime_disable(&pdev->dev);
@@ -2850,7 +2857,7 @@ static int cpsw_remove(struct platform_device *pdev)
2850 2857
2851 cpsw_ale_destroy(cpsw->ale); 2858 cpsw_ale_destroy(cpsw->ale);
2852 cpdma_ctlr_destroy(cpsw->dma); 2859 cpdma_ctlr_destroy(cpsw->dma);
2853 of_platform_depopulate(&pdev->dev); 2860 cpsw_remove_dt(pdev);
2854 pm_runtime_put_sync(&pdev->dev); 2861 pm_runtime_put_sync(&pdev->dev);
2855 pm_runtime_disable(&pdev->dev); 2862 pm_runtime_disable(&pdev->dev);
2856 if (cpsw->data.dual_emac) 2863 if (cpsw->data.dual_emac)