From patchwork Sat Sep 7 03:10:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 826358 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B73023D97F; Sat, 7 Sep 2024 03:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678093; cv=none; b=q9V3RX270xcvRSyOwZ1F0ok6kMrG0SNOtDZDBZG+HA8ddBHCPG4Z5194deLj1Ft2kkmP8fC5n2OJFRFvgXKiy4QcpVhOJzkFmgkjKpMH+Yd6cPAgwj1b08n0RfS4mfNGgCs3U4iDN8wLGLk5HIXGBIjkWlj/solYg0c0lexKh1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678093; c=relaxed/simple; bh=uuPsbGSC03RIrdjCtzWhXiL4H5CVg5+9qxkQe4VXg8M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Iuha5nrnZubehj5OFy3omFyYfwOTFYri9e84LF3uyDpXpkZASg1OBDcVTcy4iphCyFlOQ9DhesOKlVWs8vrI9hGBf1AajihVUbvzFB810mth41BXc/Uumf5bdo9UEmhCsqes0pDqltmun1pTHRiAJZcSspScosu/uydUjojHAX8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4X0yXV32zwz1S9mZ; Sat, 7 Sep 2024 11:00:58 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id C24471A016C; Sat, 7 Sep 2024 11:01:22 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Sat, 7 Sep 2024 11:01:21 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , Subject: [PATCH net-next v2 02/10] net: ethernet: Convert using devm_clk_get_enabled() in emac_probe() Date: Sat, 7 Sep 2024 11:10:01 +0800 Message-ID: <20240907031009.3591057-4-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240907031009.3591057-1-lizetao1@huawei.com> References: <20240907031009.3591057-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd500012.china.huawei.com (7.221.188.25) Use devm_clk_get_enabled() instead of devm_clk_get() + clk_prepare_enable(), which can make the clk consistent with the device life cycle and reduce the risk of unreleased clk resources. Since the device framework has automatically released the clk resource, there is no need to execute clk_disable_unprepare(clk) on the error path, drop the out_clk_disable_unprepare label, and the original error process can changed to the out_dispose_mapping error path. Signed-off-by: Li Zetao --- drivers/net/ethernet/allwinner/sun4i-emac.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/allwinner/sun4i-emac.c b/drivers/net/ethernet/allwinner/sun4i-emac.c index d761c08fe5c1..8f42501729b7 100644 --- a/drivers/net/ethernet/allwinner/sun4i-emac.c +++ b/drivers/net/ethernet/allwinner/sun4i-emac.c @@ -1005,22 +1005,16 @@ static int emac_probe(struct platform_device *pdev) if (emac_configure_dma(db)) netdev_info(ndev, "configure dma failed. disable dma.\n"); - db->clk = devm_clk_get(&pdev->dev, NULL); + db->clk = devm_clk_get_enabled(&pdev->dev, NULL); if (IS_ERR(db->clk)) { ret = PTR_ERR(db->clk); goto out_dispose_mapping; } - ret = clk_prepare_enable(db->clk); - if (ret) { - dev_err(&pdev->dev, "Error couldn't enable clock (%d)\n", ret); - goto out_dispose_mapping; - } - ret = sunxi_sram_claim(&pdev->dev); if (ret) { dev_err(&pdev->dev, "Error couldn't map SRAM to device\n"); - goto out_clk_disable_unprepare; + goto out_dispose_mapping; } db->phy_node = of_parse_phandle(np, "phy-handle", 0); @@ -1068,8 +1062,6 @@ static int emac_probe(struct platform_device *pdev) out_release_sram: sunxi_sram_release(&pdev->dev); -out_clk_disable_unprepare: - clk_disable_unprepare(db->clk); out_dispose_mapping: irq_dispose_mapping(ndev->irq); dma_release_channel(db->rx_chan); @@ -1095,7 +1087,6 @@ static void emac_remove(struct platform_device *pdev) unregister_netdev(ndev); sunxi_sram_release(&pdev->dev); - clk_disable_unprepare(db->clk); irq_dispose_mapping(ndev->irq); iounmap(db->membase); free_netdev(ndev); From patchwork Sat Sep 7 03:19:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 826355 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A23C7249EB; Sat, 7 Sep 2024 03:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678645; cv=none; b=fBeE/F10/2XDeDSrap1WHwNxuzPQX15VaDScBN3dEchqmdYFOmFj40LGBVvuEIjXavt+BqDhNa8axTLrKL968dzSUSyLRfAGdAFiXMuy8cIsPEFRjjQbGKKX3CdFen7v74lXOs9QSCTnVKLFNBv6I1ppsITwlHTXZF8eFJGWVHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678645; c=relaxed/simple; bh=CJkyw4Pe6fR3XV4v8fZkKyySghrcwh8OHib7UMXEgUQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=J3XFanjVEwZ9FSLTws6X4VbiVFGWV/ZbOhZej67/ME+U9m7lmmqmasjYpHmc/yuOXfkF6ltmrPefLf/hoy7hyD2f/VieQWsDNIxbf+r5en5rdnm4XR4/bw2CUlMiLLPZLarro5PEbny1lTicVvMoWY/Pxyqc7zfdujJZTRHLHRU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4X0ylF1951z1S72W; Sat, 7 Sep 2024 11:10:17 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 83B8E1400CF; Sat, 7 Sep 2024 11:10:41 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Sat, 7 Sep 2024 11:10:40 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH net-next v2 04/10] net: ethernet: ethoc: Convert using devm_clk_get_enabled() in ethoc_probe() Date: Sat, 7 Sep 2024 11:19:20 +0800 Message-ID: <20240907031926.3591353-5-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240907031926.3591353-1-lizetao1@huawei.com> References: <20240907031926.3591353-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd500012.china.huawei.com (7.221.188.25) Use devm_clk_get_enabled() instead of devm_clk_get() + clk_prepare_enable(), which can make the clk consistent with the device life cycle and reduce the risk of unreleased clk resources. Since the device framework has automatically released the clk resource, there is no need to execute clk_disable_unprepare(clk) on the error path, drop the free2 label, and the meaning of the free3 label is not clear, Changing it to free_mdiobus will make it more understandable. Signed-off-by: Li Zetao --- drivers/net/ethernet/ethoc.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c index ad41c9019018..1a56e20cb679 100644 --- a/drivers/net/ethernet/ethoc.c +++ b/drivers/net/ethernet/ethoc.c @@ -1172,13 +1172,10 @@ static int ethoc_probe(struct platform_device *pdev) /* Allow the platform setup code to adjust MII management bus clock. */ if (!eth_clkfreq) { - struct clk *clk = devm_clk_get(&pdev->dev, NULL); + priv->clk = devm_clk_get_enabled(&pdev->dev, NULL); - if (!IS_ERR(clk)) { - priv->clk = clk; - clk_prepare_enable(clk); - eth_clkfreq = clk_get_rate(clk); - } + if (!IS_ERR(priv->clk)) + eth_clkfreq = clk_get_rate(priv->clk); } if (eth_clkfreq) { u32 clkdiv = MIIMODER_CLKDIV(eth_clkfreq / 2500000 + 1); @@ -1195,7 +1192,7 @@ static int ethoc_probe(struct platform_device *pdev) priv->mdio = mdiobus_alloc(); if (!priv->mdio) { ret = -ENOMEM; - goto free2; + goto free; } priv->mdio->name = "ethoc-mdio"; @@ -1208,7 +1205,7 @@ static int ethoc_probe(struct platform_device *pdev) ret = mdiobus_register(priv->mdio); if (ret) { dev_err(&netdev->dev, "failed to register MDIO bus\n"); - goto free3; + goto free_mdiobus; } ret = ethoc_mdio_probe(netdev); @@ -1240,10 +1237,8 @@ static int ethoc_probe(struct platform_device *pdev) netif_napi_del(&priv->napi); error: mdiobus_unregister(priv->mdio); -free3: +free_mdiobus: mdiobus_free(priv->mdio); -free2: - clk_disable_unprepare(priv->clk); free: free_netdev(netdev); out: @@ -1267,7 +1262,6 @@ static void ethoc_remove(struct platform_device *pdev) mdiobus_unregister(priv->mdio); mdiobus_free(priv->mdio); } - clk_disable_unprepare(priv->clk); unregister_netdev(netdev); free_netdev(netdev); } From patchwork Sat Sep 7 03:19:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 826354 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27E7A13A86A; Sat, 7 Sep 2024 03:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678648; cv=none; b=XAGV9IKEiIR8v9eRVuFIl91BGNOesbgUGWBWPvIHUj5uQCj6WbO+ntUpRZ0eg0Y7qzhoZLhcwvVrmK5v4XvWmCHOtVNAYwJOIxxoqRHr2mSsyOq4wmP6NvUtIPlEmkfT6HWbPJsZGAVApjRJ1feIpQHhj0w1xR2ZQhiDO9SQ10k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678648; c=relaxed/simple; bh=3b+7A5e6yMhko3erhk5rlZdd6Ltt1amgAMxhEwLvi74=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z3kIsYBTIHphJZ54PoN3Ln9UpIbxuRem8vhtQebYewM01kmid7TfXUbanwPx9EsfpfgHbK/KuH7LbMQEKU4wZaZBFw/7Ygwp1fdW4imFQ2+zqLslU9PJ2eC/u7i9hJmaqm5uGNnH3/hxmae8F5RrI1lhWGbRyQ6+1qNBu/zRzh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4X0ykY4WdMz1BHxN; Sat, 7 Sep 2024 11:09:41 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 892C11402C8; Sat, 7 Sep 2024 11:10:42 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Sat, 7 Sep 2024 11:10:41 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH net-next v2 05/10] net: ftgmac100: Convert using devm_clk_get_enabled() in ftgmac100_setup_clk() Date: Sat, 7 Sep 2024 11:19:21 +0800 Message-ID: <20240907031926.3591353-6-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240907031926.3591353-1-lizetao1@huawei.com> References: <20240907031926.3591353-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd500012.china.huawei.com (7.221.188.25) Use devm_clk_get_enabled() instead of devm_clk_get() + clk_prepare_enable(), which can make the clk consistent with the device life cycle and reduce the risk of unreleased clk resources. Since the device framework has automatically released the clk resource, there is no need to execute clk_disable_unprepare(clk) on the error path, drop the cleanup_clk label, and the original error process can return directly. It turns out that checking the return value of clk_prepare_enable is a bit counter-intuitive. Here use PTR_ERR_OR_ZERO to make it more intuitive. Signed-off-by: Li Zetao --- v1 -> v2: Optimize return value checking and add commit information for easy understanding v1: https://lore.kernel.org/all/20240831021334.1907921-6-lizetao1@huawei.com/ drivers/net/ethernet/faraday/ftgmac100.c | 26 +++++------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c index f3cc14cc757d..f2911507d7b8 100644 --- a/drivers/net/ethernet/faraday/ftgmac100.c +++ b/drivers/net/ethernet/faraday/ftgmac100.c @@ -1767,13 +1767,10 @@ static int ftgmac100_setup_clk(struct ftgmac100 *priv) struct clk *clk; int rc; - clk = devm_clk_get(priv->dev, NULL /* MACCLK */); + clk = devm_clk_get_enabled(priv->dev, NULL /* MACCLK */); if (IS_ERR(clk)) return PTR_ERR(clk); priv->clk = clk; - rc = clk_prepare_enable(priv->clk); - if (rc) - return rc; /* Aspeed specifies a 100MHz clock is required for up to * 1000Mbit link speeds. As NCSI is limited to 100Mbit, 25MHz @@ -1782,21 +1779,14 @@ static int ftgmac100_setup_clk(struct ftgmac100 *priv) rc = clk_set_rate(priv->clk, priv->use_ncsi ? FTGMAC_25MHZ : FTGMAC_100MHZ); if (rc) - goto cleanup_clk; + return rc; /* RCLK is for RMII, typically used for NCSI. Optional because it's not * necessary if it's the AST2400 MAC, or the MAC is configured for * RGMII, or the controller is not an ASPEED-based controller. */ - priv->rclk = devm_clk_get_optional(priv->dev, "RCLK"); - rc = clk_prepare_enable(priv->rclk); - if (!rc) - return 0; - -cleanup_clk: - clk_disable_unprepare(priv->clk); - - return rc; + priv->rclk = devm_clk_get_optional_enabled(priv->dev, "RCLK"); + return PTR_ERR_OR_ZERO(priv->rclk); } static bool ftgmac100_has_child_node(struct device_node *np, const char *name) @@ -2020,16 +2010,13 @@ static int ftgmac100_probe(struct platform_device *pdev) err = register_netdev(netdev); if (err) { dev_err(&pdev->dev, "Failed to register netdev\n"); - goto err_register_netdev; + goto err_phy_connect; } netdev_info(netdev, "irq %d, mapped at %p\n", netdev->irq, priv->base); return 0; -err_register_netdev: - clk_disable_unprepare(priv->rclk); - clk_disable_unprepare(priv->clk); err_phy_connect: ftgmac100_phy_disconnect(netdev); err_ncsi_dev: @@ -2058,9 +2045,6 @@ static void ftgmac100_remove(struct platform_device *pdev) ncsi_unregister_dev(priv->ndev); unregister_netdev(netdev); - clk_disable_unprepare(priv->rclk); - clk_disable_unprepare(priv->clk); - /* There's a small chance the reset task will have been re-queued, * during stop, make sure it's gone before we free the structure. */ From patchwork Sat Sep 7 03:19:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 826353 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E43314B94B; Sat, 7 Sep 2024 03:10:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678649; cv=none; b=LlYDr0zQYGqQ6diaXXuzEXmjEpoT8Z5IntKVC37tix/mrdyu1FSFaJ78nq/rx7NRHNqHFrbUXFnu2jOnTSqWeCJBngJkeUKWJ+CNelk/3T/RI/xCe29Ml/k9WCBO5pXUuvzYDL4w0wLqA7txxA5o7s6z3ECgsIB+1Ct5RLYOWvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678649; c=relaxed/simple; bh=NTT6omI+1h722IadGdfo3Cu5+r9CNZ+yAF34IF8fqzU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dqeCpKlSn1UkwOpdi3c91RC8i6zLszovHmEcpr6LWG8FayiYVCzkB1j2OeZ4PAtlQ15KjUC+GJnM6pOBfe6GV+raxTwd8FdweeHZ0gJJLFckgIiKsUoDbQ9mNKkv+hE0K7XjAlDSxx01vzgUi4vchw48n3HriGkV8Gpr7z/i2kw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4X0ylK04f0z1j80G; Sat, 7 Sep 2024 11:10:21 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 96AEE14011F; Sat, 7 Sep 2024 11:10:44 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Sat, 7 Sep 2024 11:10:43 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH net-next v2 07/10] net: lantiq_xrx200: Convert using devm_clk_get_enabled() in xrx200_probe() Date: Sat, 7 Sep 2024 11:19:23 +0800 Message-ID: <20240907031926.3591353-8-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240907031926.3591353-1-lizetao1@huawei.com> References: <20240907031926.3591353-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd500012.china.huawei.com (7.221.188.25) Use devm_clk_get_enabled() instead of devm_clk_get() + clk_prepare_enable(), which can make the clk consistent with the device life cycle and reduce the risk of unreleased clk resources. Since the device framework has automatically released the clk resource, there is no need to execute clk_disable_unprepare(clk) on the error path, drop the err_unprepare_clk label, and the original error process can change to the err_uninit_dma error path. Some comments have also been adjusted. Signed-off-by: Li Zetao --- drivers/net/ethernet/lantiq_xrx200.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/lantiq_xrx200.c b/drivers/net/ethernet/lantiq_xrx200.c index 07904a528f21..976748551643 100644 --- a/drivers/net/ethernet/lantiq_xrx200.c +++ b/drivers/net/ethernet/lantiq_xrx200.c @@ -589,8 +589,8 @@ static int xrx200_probe(struct platform_device *pdev) if (priv->chan_tx.dma.irq < 0) return -ENOENT; - /* get the clock */ - priv->clk = devm_clk_get(dev, NULL); + /* get the clock and enable clock gate */ + priv->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(priv->clk)) { dev_err(dev, "failed to get clock\n"); return PTR_ERR(priv->clk); @@ -605,11 +605,6 @@ static int xrx200_probe(struct platform_device *pdev) if (err) return err; - /* enable clock gate */ - err = clk_prepare_enable(priv->clk); - if (err) - goto err_uninit_dma; - /* set IPG to 12 */ xrx200_pmac_mask(priv, PMAC_RX_IPG_MASK, 0xb, PMAC_RX_IPG); @@ -628,13 +623,10 @@ static int xrx200_probe(struct platform_device *pdev) err = register_netdev(net_dev); if (err) - goto err_unprepare_clk; + goto err_uninit_dma; return 0; -err_unprepare_clk: - clk_disable_unprepare(priv->clk); - err_uninit_dma: xrx200_hw_cleanup(priv); @@ -654,9 +646,6 @@ static void xrx200_remove(struct platform_device *pdev) /* remove the actual device */ unregister_netdev(net_dev); - /* release the clock */ - clk_disable_unprepare(priv->clk); - /* shut down hardware */ xrx200_hw_cleanup(priv); } From patchwork Sat Sep 7 03:10:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 826359 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECC364084E; Sat, 7 Sep 2024 03:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678092; cv=none; b=haRz9bU8Vg3lP9WOJ9S22k8smPtrpf6hAZ4Fd/1wX2QA1q3OZnNkCa6YblfGGfDKgZgiB0pwggWN/QJ/yMPNXMx6hYUELNw+pBvEfvOcfm6bLG3xUFdfTnMdAnEH9VvpuABbDEZ/8/ZKyOqp1/xbN5TVIeHMCEB/s8Ql3NH8KNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678092; c=relaxed/simple; bh=7W1tcdm2zh5G5w60OHuhn10sbehAYbPyEfodQj/6jmU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TEYbstMJJ0gdn2xuon8HaaeAMMG7hpvYvoRoim7gLk7xqlDMpicHEvxuI7ZK/dNz9Y5KUJUValCJ+tRFnE6Y8u5pO05KgckSgMH/N1BACHTryoB/CRmTttc3lx5FcmroYW/16sh3925bn9YkY7V/JAN3iI/ziTbBgf1tNmhpVV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4X0yT20Tvrz1HJL8; Sat, 7 Sep 2024 10:57:58 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 75D881400D3; Sat, 7 Sep 2024 11:01:28 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Sat, 7 Sep 2024 11:01:27 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , Subject: [PATCH net-next v2 08/10] net: stmmac: dwmac-dwc-qos-eth: Convert using devm_clk_get_enabled() in dwc_qos_probe() Date: Sat, 7 Sep 2024 11:10:07 +0800 Message-ID: <20240907031009.3591057-10-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240907031009.3591057-1-lizetao1@huawei.com> References: <20240907031009.3591057-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd500012.china.huawei.com (7.221.188.25) Use devm_clk_get_enabled() instead of devm_clk_get() + clk_prepare_enable(), which can make the clk consistent with the device life cycle and reduce the risk of unreleased clk resources. Since the device framework has automatically released the clk resource, there is no need to execute clk_disable_unprepare(clk) on the error path, drop the disable label, and the original error process can return directly. The tegra_eqos_probe() also has similar modifications. Signed-off-by: Li Zetao --- .../stmicro/stmmac/dwmac-dwc-qos-eth.c | 98 ++++--------------- 1 file changed, 17 insertions(+), 81 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c index ec924c6c76c6..d6e9a93771f4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c @@ -123,49 +123,24 @@ static int dwc_qos_probe(struct platform_device *pdev, struct plat_stmmacenet_data *plat_dat, struct stmmac_resources *stmmac_res) { - int err; - - plat_dat->stmmac_clk = devm_clk_get(&pdev->dev, "apb_pclk"); + plat_dat->stmmac_clk = devm_clk_get_enabled(&pdev->dev, "apb_pclk"); if (IS_ERR(plat_dat->stmmac_clk)) { dev_err(&pdev->dev, "apb_pclk clock not found.\n"); return PTR_ERR(plat_dat->stmmac_clk); } - err = clk_prepare_enable(plat_dat->stmmac_clk); - if (err < 0) { - dev_err(&pdev->dev, "failed to enable apb_pclk clock: %d\n", - err); - return err; - } - - plat_dat->pclk = devm_clk_get(&pdev->dev, "phy_ref_clk"); + plat_dat->pclk = devm_clk_get_enabled(&pdev->dev, "phy_ref_clk"); if (IS_ERR(plat_dat->pclk)) { dev_err(&pdev->dev, "phy_ref_clk clock not found.\n"); - err = PTR_ERR(plat_dat->pclk); - goto disable; - } - - err = clk_prepare_enable(plat_dat->pclk); - if (err < 0) { - dev_err(&pdev->dev, "failed to enable phy_ref clock: %d\n", - err); - goto disable; + return PTR_ERR(plat_dat->pclk); } return 0; - -disable: - clk_disable_unprepare(plat_dat->stmmac_clk); - return err; } static void dwc_qos_remove(struct platform_device *pdev) { - struct net_device *ndev = platform_get_drvdata(pdev); - struct stmmac_priv *priv = netdev_priv(ndev); - clk_disable_unprepare(priv->plat->pclk); - clk_disable_unprepare(priv->plat->stmmac_clk); } #define SDMEMCOMPPADCTRL 0x8800 @@ -283,53 +258,27 @@ static int tegra_eqos_probe(struct platform_device *pdev, if (!is_of_node(dev->fwnode)) goto bypass_clk_reset_gpio; - eqos->clk_master = devm_clk_get(&pdev->dev, "master_bus"); - if (IS_ERR(eqos->clk_master)) { - err = PTR_ERR(eqos->clk_master); - goto error; - } + eqos->clk_master = devm_clk_get_enabled(&pdev->dev, "master_bus"); + if (IS_ERR(eqos->clk_master)) + return PTR_ERR(eqos->clk_master); - err = clk_prepare_enable(eqos->clk_master); - if (err < 0) - goto error; - - eqos->clk_slave = devm_clk_get(&pdev->dev, "slave_bus"); - if (IS_ERR(eqos->clk_slave)) { - err = PTR_ERR(eqos->clk_slave); - goto disable_master; - } + eqos->clk_slave = devm_clk_get_enabled(&pdev->dev, "slave_bus"); + if (IS_ERR(eqos->clk_slave)) + return PTR_ERR(eqos->clk_slave); data->stmmac_clk = eqos->clk_slave; - err = clk_prepare_enable(eqos->clk_slave); - if (err < 0) - goto disable_master; - - eqos->clk_rx = devm_clk_get(&pdev->dev, "rx"); - if (IS_ERR(eqos->clk_rx)) { - err = PTR_ERR(eqos->clk_rx); - goto disable_slave; - } - - err = clk_prepare_enable(eqos->clk_rx); - if (err < 0) - goto disable_slave; + eqos->clk_rx = devm_clk_get_enabled(&pdev->dev, "rx"); + if (IS_ERR(eqos->clk_rx)) + return PTR_ERR(eqos->clk_rx); - eqos->clk_tx = devm_clk_get(&pdev->dev, "tx"); - if (IS_ERR(eqos->clk_tx)) { - err = PTR_ERR(eqos->clk_tx); - goto disable_rx; - } - - err = clk_prepare_enable(eqos->clk_tx); - if (err < 0) - goto disable_rx; + eqos->clk_tx = devm_clk_get_enabled(&pdev->dev, "tx"); + if (IS_ERR(eqos->clk_tx)) + return PTR_ERR(eqos->clk_tx); eqos->reset = devm_gpiod_get(&pdev->dev, "phy-reset", GPIOD_OUT_HIGH); - if (IS_ERR(eqos->reset)) { - err = PTR_ERR(eqos->reset); - goto disable_tx; - } + if (IS_ERR(eqos->reset)) + return PTR_ERR(eqos->reset); usleep_range(2000, 4000); gpiod_set_value(eqos->reset, 0); @@ -370,15 +319,6 @@ static int tegra_eqos_probe(struct platform_device *pdev, reset_control_assert(eqos->rst); reset_phy: gpiod_set_value(eqos->reset, 1); -disable_tx: - clk_disable_unprepare(eqos->clk_tx); -disable_rx: - clk_disable_unprepare(eqos->clk_rx); -disable_slave: - clk_disable_unprepare(eqos->clk_slave); -disable_master: - clk_disable_unprepare(eqos->clk_master); -error: return err; } @@ -388,10 +328,6 @@ static void tegra_eqos_remove(struct platform_device *pdev) reset_control_assert(eqos->rst); gpiod_set_value(eqos->reset, 1); - clk_disable_unprepare(eqos->clk_tx); - clk_disable_unprepare(eqos->clk_rx); - clk_disable_unprepare(eqos->clk_slave); - clk_disable_unprepare(eqos->clk_master); } struct dwc_eth_dwmac_data { From patchwork Sat Sep 7 03:19:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 826352 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC4FC1514CB; Sat, 7 Sep 2024 03:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678650; cv=none; b=Jm85asv+MSMWl+Rl/7Kv0ApQSYLO3wgOgxd4oGWeCtAm9MZg1V4MI8Za1Zjm5fCWwqVzoDIN8JOwRh91bkQnPlfyR4vTaNemTfkC6cLaGn2vdpurxWJX9SA6q1XKCehd2574i4V57Kk9CrtSqRZhEEOT5VREngofkp6lVhvksTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678650; c=relaxed/simple; bh=3LkLjxpWEKDfGssDbCj1BcZ6R0Gz4xgvQlw3VPzlsf0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N9xHPLSgbeMC4R0JNwsrHWuF3OQZs3tK/cfiou1NKf3GyCFCjFjz5zp4DOTjCwG8ZZsL8eKhh+gbkCur1GSLgvhSO41ZxOiIPq1ftgspBz1fu5zQXMkRYznFgj1fIpPRR/XtNgjjtjmLEkT8EXy49+Y9BeDAVJTmUdCYL9zwLIk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4X0yln13H6z69WR; Sat, 7 Sep 2024 11:10:45 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 90FCB1800CF; Sat, 7 Sep 2024 11:10:46 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Sat, 7 Sep 2024 11:10:45 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH net-next v2 09/10] net: ethernet: sunplus: Convert using devm_clk_get_enabled() in spl2sw_probe() Date: Sat, 7 Sep 2024 11:19:25 +0800 Message-ID: <20240907031926.3591353-10-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240907031926.3591353-1-lizetao1@huawei.com> References: <20240907031926.3591353-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd500012.china.huawei.com (7.221.188.25) Use devm_clk_get_enabled() instead of devm_clk_get() + clk_prepare_enable(), which can make the clk consistent with the device life cycle and reduce the risk of unreleased clk resources. Since the device framework has automatically released the clk resource, there is no need to execute clk_disable_unprepare(clk) on the error path, drop the out_clk_disable label, and the original error process can return directly. Some comments have also been adjusted. After this modification , it is no longer necessary to use clk, so delete the clk member of the spl2sw_common structure. Signed-off-by: Li Zetao --- v1 -> v2: Delete the clk member of the spl2sw_common structure v1: https://lore.kernel.org/all/20240831021334.1907921-10-lizetao1@huawei.com/ drivers/net/ethernet/sunplus/spl2sw_define.h | 1 - drivers/net/ethernet/sunplus/spl2sw_driver.c | 25 +++++++------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/sunplus/spl2sw_define.h b/drivers/net/ethernet/sunplus/spl2sw_define.h index acc6c1228ebc..6318eccc6c4e 100644 --- a/drivers/net/ethernet/sunplus/spl2sw_define.h +++ b/drivers/net/ethernet/sunplus/spl2sw_define.h @@ -224,7 +224,6 @@ struct spl2sw_common { struct platform_device *pdev; struct reset_control *rstc; - struct clk *clk; void *desc_base; dma_addr_t desc_dma; diff --git a/drivers/net/ethernet/sunplus/spl2sw_driver.c b/drivers/net/ethernet/sunplus/spl2sw_driver.c index 391a1bc7f446..887da05bc204 100644 --- a/drivers/net/ethernet/sunplus/spl2sw_driver.c +++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c @@ -327,6 +327,7 @@ static int spl2sw_probe(struct platform_device *pdev) struct net_device *ndev; struct spl2sw_mac *mac; u8 mac_addr[ETH_ALEN]; + struct clk *clk; int irq, i, ret; if (platform_get_drvdata(pdev)) @@ -355,12 +356,12 @@ static int spl2sw_probe(struct platform_device *pdev) return ret; irq = ret; - /* Get clock controller. */ - comm->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(comm->clk)) { - dev_err_probe(&pdev->dev, PTR_ERR(comm->clk), + /* Get and enable clock controller. */ + clk = devm_clk_get_enabled(&pdev->dev, NULL); + if (IS_ERR(clk)) { + dev_err_probe(&pdev->dev, PTR_ERR(clk), "Failed to retrieve clock controller!\n"); - return PTR_ERR(comm->clk); + return PTR_ERR(clk); } /* Get reset controller. */ @@ -371,10 +372,6 @@ static int spl2sw_probe(struct platform_device *pdev) return PTR_ERR(comm->rstc); } - /* Enable clock. */ - ret = clk_prepare_enable(comm->clk); - if (ret) - return ret; udelay(1); /* Reset MAC */ @@ -388,7 +385,7 @@ static int spl2sw_probe(struct platform_device *pdev) dev_name(&pdev->dev), comm); if (ret) { dev_err(&pdev->dev, "Failed to request irq #%d!\n", irq); - goto out_clk_disable; + return ret; } /* Initialize TX and RX descriptors. */ @@ -396,7 +393,7 @@ static int spl2sw_probe(struct platform_device *pdev) if (ret) { dev_err(&pdev->dev, "Fail to initialize mac descriptors!\n"); spl2sw_descs_free(comm); - goto out_clk_disable; + return ret; } /* Initialize MAC. */ @@ -406,7 +403,7 @@ static int spl2sw_probe(struct platform_device *pdev) ret = spl2sw_mdio_init(comm); if (ret) { dev_err(&pdev->dev, "Failed to initialize mdio bus!\n"); - goto out_clk_disable; + return ret; } /* Get child node ethernet-ports. */ @@ -506,8 +503,6 @@ static int spl2sw_probe(struct platform_device *pdev) out_free_mdio: spl2sw_mdio_remove(comm); -out_clk_disable: - clk_disable_unprepare(comm->clk); return ret; } @@ -536,8 +531,6 @@ static void spl2sw_remove(struct platform_device *pdev) netif_napi_del(&comm->tx_napi); spl2sw_mdio_remove(comm); - - clk_disable_unprepare(comm->clk); } static const struct of_device_id spl2sw_of_match[] = { From patchwork Sat Sep 7 03:10:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 826357 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 709F643ACB; Sat, 7 Sep 2024 03:01:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678096; cv=none; b=Mi8LVcKFi722pQZpYn6ljrXlIXh/px5siauO29etOpFyCMrz43ZGt8qUecf8BA9uVyF5BC6RC4XBoWPxhfRuKIDA+a4rVc9SjgHW2lxwEBytgWePA7cOITvWmu7Xvz3U/P0Pr+T+lIZdQ8w6cg1SMwFl5D+jzz/CFMJgVKyQbp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678096; c=relaxed/simple; bh=QTU7fufNN1BaBlcJYY1qHswGUbgAx/DUxgQa8eGoits=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aliEXJB4cB8L0EVUC8i1w8NPT4T1c+kt/MJCv4GFt5gvZxFpkTppNln/wNflwNZog/1t5sIh6d19O4QdQlE1V8hCkF7B+/WcmujxJnDjnlO8uQGof6jltuVIxdX33HPIuqwsayi8DlPrOEf9Zq05vpthSU9oS4mil9EPOsbTyUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4X0yRL2ZlSz20nY1; Sat, 7 Sep 2024 10:56:30 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 5BFA91A0188; Sat, 7 Sep 2024 11:01:30 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Sat, 7 Sep 2024 11:01:29 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , Subject: [PATCH net-next v2 10/10] net: xilinx: axienet: Convert using devm_clk_get_optional_enabled() in axienet_probe() Date: Sat, 7 Sep 2024 11:10:09 +0800 Message-ID: <20240907031009.3591057-12-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240907031009.3591057-1-lizetao1@huawei.com> References: <20240907031009.3591057-1-lizetao1@huawei.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd500012.china.huawei.com (7.221.188.25) Use devm_clk_get_optional_enabled() instead of devm_clk_get_optional() + clk_prepare_enable(), which can make the clk consistent with the device life cycle and reduce the risk of unreleased clk resources. Since the device framework has automatically released the clk resource, there is no need to execute clk_disable_unprepare(clk) on the error path. Reviewed-by: Radhey Shyam Pandey Signed-off-by: Li Zetao --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 374dff70ef0d..87c5dcec2325 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -2592,22 +2592,17 @@ static int axienet_probe(struct platform_device *pdev) seqcount_mutex_init(&lp->hw_stats_seqcount, &lp->stats_lock); INIT_DEFERRABLE_WORK(&lp->stats_work, axienet_refresh_stats); - lp->axi_clk = devm_clk_get_optional(&pdev->dev, "s_axi_lite_clk"); - if (!lp->axi_clk) { + lp->axi_clk = devm_clk_get_optional_enabled(&pdev->dev, "s_axi_lite_clk"); + if (!lp->axi_clk) /* For backward compatibility, if named AXI clock is not present, * treat the first clock specified as the AXI clock. */ - lp->axi_clk = devm_clk_get_optional(&pdev->dev, NULL); - } + lp->axi_clk = devm_clk_get_optional_enabled(&pdev->dev, NULL); + if (IS_ERR(lp->axi_clk)) { ret = PTR_ERR(lp->axi_clk); goto free_netdev; } - ret = clk_prepare_enable(lp->axi_clk); - if (ret) { - dev_err(&pdev->dev, "Unable to enable AXI clock: %d\n", ret); - goto free_netdev; - } lp->misc_clks[0].id = "axis_clk"; lp->misc_clks[1].id = "ref_clk"; @@ -2923,7 +2918,6 @@ static int axienet_probe(struct platform_device *pdev) axienet_mdio_teardown(lp); cleanup_clk: clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, lp->misc_clks); - clk_disable_unprepare(lp->axi_clk); free_netdev: free_netdev(ndev); @@ -2947,7 +2941,6 @@ static void axienet_remove(struct platform_device *pdev) axienet_mdio_teardown(lp); clk_bulk_disable_unprepare(XAE_NUM_MISC_CLOCKS, lp->misc_clks); - clk_disable_unprepare(lp->axi_clk); free_netdev(ndev); }