From: Christophe JAILLET Update error handling of probe function. Signed-off-by: Christophe JAILLET Signed-off-by: Michael Dege --- drivers/net/ethernet/renesas/rswitch_main.c | 63 ++++++++++++++++------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/drivers/net/ethernet/renesas/rswitch_main.c b/drivers/net/ethernet/renesas/rswitch_main.c index 8d56ef037a8d..1d8f141a25d3 100644 --- a/drivers/net/ethernet/renesas/rswitch_main.c +++ b/drivers/net/ethernet/renesas/rswitch_main.c @@ -2231,6 +2231,30 @@ static const struct soc_device_attribute rswitch_soc_no_speed_change[] = { { /* Sentinel */ } }; +static void rswitch_deinit(struct rswitch_private *priv) +{ + unsigned int i; + + rswitch_gwca_hw_deinit(priv); + rcar_gen4_ptp_unregister(priv->ptp_priv); + + rswitch_for_each_enabled_port(priv, i) { + struct rswitch_device *rdev = priv->rdev[i]; + + unregister_netdev(rdev->ndev); + rswitch_ether_port_deinit_one(rdev); + phy_exit(priv->rdev[i]->serdes); + } + + for (i = 0; i < RSWITCH_NUM_PORTS; i++) + rswitch_device_free(priv, i); + + rswitch_gwca_ts_queue_free(priv); + rswitch_gwca_linkfix_free(priv); + + rswitch_clock_disable(priv); +} + static int renesas_eth_sw_probe(struct platform_device *pdev) { const struct soc_device_attribute *attr; @@ -2294,11 +2318,8 @@ static int renesas_eth_sw_probe(struct platform_device *pdev) pm_runtime_get_sync(&pdev->dev); ret = rswitch_init(priv); - if (ret < 0) { - pm_runtime_put(&pdev->dev); - pm_runtime_disable(&pdev->dev); - return ret; - } + if (ret < 0) + goto err_disable_pm_runtime; if (list_empty(&priv->port_list)) dev_warn(&pdev->dev, "could not initialize any ports\n"); @@ -2306,36 +2327,20 @@ static int renesas_eth_sw_probe(struct platform_device *pdev) ret = rswitch_register_notifiers(); if (ret) { dev_err(&pdev->dev, "could not register notifiers\n"); - return ret; + goto err_deinit_rswitch; } device_set_wakeup_capable(&pdev->dev, 1); - return ret; -} - -static void rswitch_deinit(struct rswitch_private *priv) -{ - unsigned int i; - - rswitch_gwca_hw_deinit(priv); - rcar_gen4_ptp_unregister(priv->ptp_priv); - - rswitch_for_each_enabled_port(priv, i) { - struct rswitch_device *rdev = priv->rdev[i]; - - unregister_netdev(rdev->ndev); - rswitch_ether_port_deinit_one(rdev); - phy_exit(priv->rdev[i]->serdes); - } - - for (i = 0; i < RSWITCH_NUM_PORTS; i++) - rswitch_device_free(priv, i); + return 0; - rswitch_gwca_ts_queue_free(priv); - rswitch_gwca_linkfix_free(priv); +err_deinit_rswitch: + rswitch_deinit(priv); +err_disable_pm_runtime: + pm_runtime_put(&pdev->dev); + pm_runtime_disable(&pdev->dev); - rswitch_clock_disable(priv); + return ret; } static void renesas_eth_sw_remove(struct platform_device *pdev) -- 2.43.0