1 From 179a445ae4ef36ec44f4aea18e5f42d21334d186 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Sat, 25 Feb 2017 12:39:25 +0100
4 Subject: [PATCH 4/6] bcm63xx_enet: use managed functions for clock/ioremap
6 Use managed functions where possible to reduce the amount of resource
7 handling on error and remove paths.
9 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
11 drivers/net/ethernet/broadcom/bcm63xx_enet.c | 54 +++++++---------------------
12 1 file changed, 12 insertions(+), 42 deletions(-)
14 --- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
15 +++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
16 @@ -1768,14 +1768,14 @@ static int bcm_enet_probe(struct platfor
20 - priv->mac_clk = clk_get(&pdev->dev, clk_name);
21 + priv->mac_clk = devm_clk_get(&pdev->dev, clk_name);
22 if (IS_ERR(priv->mac_clk)) {
23 ret = PTR_ERR(priv->mac_clk);
26 ret = clk_prepare_enable(priv->mac_clk);
28 - goto out_put_clk_mac;
31 /* initialize default and fetch platform data */
32 priv->rx_ring_size = BCMENET_DEF_RX_DESC;
33 @@ -1803,7 +1803,7 @@ static int bcm_enet_probe(struct platfor
35 if (priv->mac_id == 0 && priv->has_phy && !priv->use_external_mii) {
36 /* using internal PHY, enable clock */
37 - priv->phy_clk = clk_get(&pdev->dev, "ephy");
38 + priv->phy_clk = devm_clk_get(&pdev->dev, "ephy");
39 if (IS_ERR(priv->phy_clk)) {
40 ret = PTR_ERR(priv->phy_clk);
42 @@ -1811,7 +1811,7 @@ static int bcm_enet_probe(struct platfor
44 ret = clk_prepare_enable(priv->phy_clk);
46 - goto out_put_clk_phy;
47 + goto out_disable_clk_mac;
50 /* do minimal hardware init to be able to probe mii bus */
51 @@ -1908,14 +1908,8 @@ out_uninit_hw:
53 clk_disable_unprepare(priv->phy_clk);
57 - clk_put(priv->phy_clk);
60 clk_disable_unprepare(priv->mac_clk);
62 - clk_put(priv->mac_clk);
66 @@ -1951,12 +1945,10 @@ static int bcm_enet_remove(struct platfo
69 /* disable hw block clocks */
70 - if (priv->phy_clk) {
72 clk_disable_unprepare(priv->phy_clk);
73 - clk_put(priv->phy_clk);
76 clk_disable_unprepare(priv->mac_clk);
77 - clk_put(priv->mac_clk);
81 @@ -2739,26 +2731,20 @@ static int bcm_enetsw_probe(struct platf
85 - if (!request_mem_region(res_mem->start, resource_size(res_mem),
86 - "bcm63xx_enetsw")) {
88 + priv->base = devm_ioremap_resource(&pdev->dev, res_mem);
89 + if (IS_ERR(priv->base)) {
90 + ret = PTR_ERR(priv->base);
94 - priv->base = ioremap(res_mem->start, resource_size(res_mem));
95 - if (priv->base == NULL) {
97 - goto out_release_mem;
100 - priv->mac_clk = clk_get(&pdev->dev, "enetsw");
101 + priv->mac_clk = devm_clk_get(&pdev->dev, "enetsw");
102 if (IS_ERR(priv->mac_clk)) {
103 ret = PTR_ERR(priv->mac_clk);
107 ret = clk_prepare_enable(priv->mac_clk);
114 @@ -2790,15 +2776,6 @@ static int bcm_enetsw_probe(struct platf
117 clk_disable_unprepare(priv->mac_clk);
120 - clk_put(priv->mac_clk);
123 - iounmap(priv->base);
126 - release_mem_region(res_mem->start, resource_size(res_mem));
130 @@ -2810,20 +2787,13 @@ static int bcm_enetsw_remove(struct plat
132 struct bcm_enet_priv *priv;
133 struct net_device *dev;
134 - struct resource *res;
137 dev = platform_get_drvdata(pdev);
138 priv = netdev_priv(dev);
139 unregister_netdev(dev);
141 - /* release device resources */
142 - iounmap(priv->base);
143 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
144 - release_mem_region(res->start, resource_size(res));
146 clk_disable_unprepare(priv->mac_clk);
147 - clk_put(priv->mac_clk);