From patchwork Sun Oct 1 11:02:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Gorski X-Patchwork-Id: 9979675 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C14A060365 for ; Sun, 1 Oct 2017 11:04:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B247B28864 for ; Sun, 1 Oct 2017 11:04:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4E6C28A28; Sun, 1 Oct 2017 11:04:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 10F8228864 for ; Sun, 1 Oct 2017 11:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=4YmbVChBdMpLzqlGGT3G/0UGqoCxDLUchq6L4ADC9wI=; b=KJXC8mRXQeJ9T2wei3RLYH01Y0 MgBno05dXEOA0KygmvuubFw9+g5NjeufPIKi35KD7w7P44T2QtxrfDVcrv9kJRUaGJIB9iAAzOsuh mQDike7v7m/il2PP0L+Bux4VwKZr11rQhXvKuve7QYZPHM2DBWH2lLKnIbwJaL8cXOmnYdkQ0ruzy UhDPhP8d7/knwewTEED3a2PR3439AuMSAjUE5NhhXz4w5t+DwZLsRDjbuaWcJZCdb6+f8LDxEsDg+ rXX8McRVg32Cmet0gy/0Es5tR8VSQYm7vSH1xv9xyYWO0hxpK94bnbi0JCrffW9AZdyXju4I8Wl7W kVDAUZbA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dyc2Y-0006Jm-3a; Sun, 01 Oct 2017 11:04:06 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dyc16-0004vf-4w for linux-arm-kernel@lists.infradead.org; Sun, 01 Oct 2017 11:02:38 +0000 Received: by mail-wm0-x241.google.com with SMTP id f4so1870324wmh.4 for ; Sun, 01 Oct 2017 04:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=76uX2SL5kQZjLEYlb3/Ppc0hH4aT8ng+PKQLsf16azY=; b=Y5JNdv/nmz5zaIfzD4ypJt38r3U91rpE4t/UJn5D7UmdZKgKGo4lvW5gf/KPuPOvJT y1Es19Ak1JDCBZV5eCQkJ9TihXVhWg/V7wAi3T+qHE28IvcNQgW2kJyOIE+c4IW16JPU lCFmodVg27eoaR4G10ylugvx2byPwAp2IVyg70Tky7JrlJMKIbtvelSnRCPc6AuCL1mb jA0Jx7ivON9t7mA9nQCx3Vin285LbhdHEzNUDa7rlYlikJQGf66yzAtanqubnqHtjvQj OVWZhJm2clMPSxgWkgCgf6GVvSMyOVQe2g/fhm69PRqmSg+x960EPzFp6iM8KeIYLE32 0Hcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=76uX2SL5kQZjLEYlb3/Ppc0hH4aT8ng+PKQLsf16azY=; b=p8qiwqoG4k1aTp0xo81E+hfyjW5tN8pKRRS+qKOXO6aqWVWwIS72fRmWDeXFNHtfjF Kj3OqWmYqZFJ5P0yKsHImL7rhE24VuEqGtCjZ/qr/8vCS7ASGyus7rXlpIyTt3bHsFXt TwG7sav5CCCnpqMidBH+nd/g1ISBnPpCveBuTXT5IYdFmt1z+ZJWZnmyKQ80B1jVyBpc 5Fov98IUkTwAlatfxkaQleA9g8iK6or+fq9DMF8zohCtccMikm5goqLlZcLRK6OgYUs6 dKG0rpepmLvQlh+bllitl5hBe1uK2N/WL0uKBSucIHJzsTbcGHp0Z30Uvw7PTqyZ1mNz 0i/Q== X-Gm-Message-State: AHPjjUjzxkw9PJm9D6waU3CyCFenW4z7OkokAgy0QnVGO8yZMNWuk/CJ 1WC/7qY4YG3dWUYUsmfG0XZWfw== X-Google-Smtp-Source: AOwi7QCX2wzv78lkzIhHAiT8PjIgcnuOPd+b1kK/7eSI9x7iH6Rh7s/YjHPMh9Gy3XQh/dNC2pA53g== X-Received: by 10.80.179.120 with SMTP id r53mr16703782edd.174.1506855735499; Sun, 01 Oct 2017 04:02:15 -0700 (PDT) Received: from localhost.localdomain ([2001:470:9e39::48e]) by smtp.gmail.com with ESMTPSA id 26sm7404270eds.5.2017.10.01.04.02.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Oct 2017 04:02:15 -0700 (PDT) From: Jonas Gorski To: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.or Subject: [PATCH 4/6] bcm63xx_enet: use managed functions for clock/ioremap Date: Sun, 1 Oct 2017 13:02:18 +0200 Message-Id: <20171001110220.27668-5-jonas.gorski@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20171001110220.27668-1-jonas.gorski@gmail.com> References: <20171001110220.27668-1-jonas.gorski@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171001_040236_374710_FE746449 X-CRM114-Status: GOOD ( 14.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Florian Fainelli , bcm-kernel-feedback-list@broadcom.com, "David S. Miller" MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Use managed functions where possible to reduce the amount of resource handling on error and remove paths. Signed-off-by: Jonas Gorski --- drivers/net/ethernet/broadcom/bcm63xx_enet.c | 54 +++++++--------------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c b/drivers/net/ethernet/broadcom/bcm63xx_enet.c index 8caf6abab3a6..059ef4f1d137 100644 --- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c +++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c @@ -1767,14 +1767,14 @@ static int bcm_enet_probe(struct platform_device *pdev) clk_name = "enet1"; } - priv->mac_clk = clk_get(&pdev->dev, clk_name); + priv->mac_clk = devm_clk_get(&pdev->dev, clk_name); if (IS_ERR(priv->mac_clk)) { ret = PTR_ERR(priv->mac_clk); goto out; } ret = clk_prepare_enable(priv->mac_clk); if (ret) - goto out_put_clk_mac; + goto out; /* initialize default and fetch platform data */ priv->rx_ring_size = BCMENET_DEF_RX_DESC; @@ -1802,7 +1802,7 @@ static int bcm_enet_probe(struct platform_device *pdev) if (priv->mac_id == 0 && priv->has_phy && !priv->use_external_mii) { /* using internal PHY, enable clock */ - priv->phy_clk = clk_get(&pdev->dev, "ephy"); + priv->phy_clk = devm_clk_get(&pdev->dev, "ephy"); if (IS_ERR(priv->phy_clk)) { ret = PTR_ERR(priv->phy_clk); priv->phy_clk = NULL; @@ -1810,7 +1810,7 @@ static int bcm_enet_probe(struct platform_device *pdev) } ret = clk_prepare_enable(priv->phy_clk); if (ret) - goto out_put_clk_phy; + goto out_disable_clk_mac; } /* do minimal hardware init to be able to probe mii bus */ @@ -1906,14 +1906,8 @@ static int bcm_enet_probe(struct platform_device *pdev) if (priv->phy_clk) clk_disable_unprepare(priv->phy_clk); -out_put_clk_phy: - if (priv->phy_clk) - clk_put(priv->phy_clk); - out_disable_clk_mac: clk_disable_unprepare(priv->mac_clk); -out_put_clk_mac: - clk_put(priv->mac_clk); out: free_netdev(dev); return ret; @@ -1949,12 +1943,10 @@ static int bcm_enet_remove(struct platform_device *pdev) } /* disable hw block clocks */ - if (priv->phy_clk) { + if (priv->phy_clk) clk_disable_unprepare(priv->phy_clk); - clk_put(priv->phy_clk); - } + clk_disable_unprepare(priv->mac_clk); - clk_put(priv->mac_clk); free_netdev(dev); return 0; @@ -2734,26 +2726,20 @@ static int bcm_enetsw_probe(struct platform_device *pdev) if (ret) goto out; - if (!request_mem_region(res_mem->start, resource_size(res_mem), - "bcm63xx_enetsw")) { - ret = -EBUSY; + priv->base = devm_ioremap_resource(&pdev->dev, res_mem); + if (IS_ERR(priv->base)) { + ret = PTR_ERR(priv->base); goto out; } - priv->base = ioremap(res_mem->start, resource_size(res_mem)); - if (priv->base == NULL) { - ret = -ENOMEM; - goto out_release_mem; - } - - priv->mac_clk = clk_get(&pdev->dev, "enetsw"); + priv->mac_clk = devm_clk_get(&pdev->dev, "enetsw"); if (IS_ERR(priv->mac_clk)) { ret = PTR_ERR(priv->mac_clk); - goto out_unmap; + goto out; } ret = clk_prepare_enable(priv->mac_clk); if (ret) - goto out_put_clk; + goto out; priv->rx_chan = 0; priv->tx_chan = 1; @@ -2785,15 +2771,6 @@ static int bcm_enetsw_probe(struct platform_device *pdev) out_disable_clk: clk_disable_unprepare(priv->mac_clk); - -out_put_clk: - clk_put(priv->mac_clk); - -out_unmap: - iounmap(priv->base); - -out_release_mem: - release_mem_region(res_mem->start, resource_size(res_mem)); out: free_netdev(dev); return ret; @@ -2805,20 +2782,13 @@ static int bcm_enetsw_remove(struct platform_device *pdev) { struct bcm_enet_priv *priv; struct net_device *dev; - struct resource *res; /* stop netdevice */ dev = platform_get_drvdata(pdev); priv = netdev_priv(dev); unregister_netdev(dev); - /* release device resources */ - iounmap(priv->base); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - release_mem_region(res->start, resource_size(res)); - clk_disable_unprepare(priv->mac_clk); - clk_put(priv->mac_clk); free_netdev(dev); return 0;