From patchwork Sat Sep 7 03:10:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 826361 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (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 37A1233991; Sat, 7 Sep 2024 03:01:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678088; cv=none; b=CSyTEdSIjj0m/lpI/Cu+Lfk9fnrfU7JOfh9qeZf/0jWb20+ivmu+ZjkwbuPsLIclT9wJXTxr+2Py4q4TpxFyn+LTUgPT3QcvYL8caRHUa1iRvW8/D/yN8FKJDwFfH0N+3kV5cEsCogoEkWE4cy0JG0xyZOmwJBy9iBkEJZtkdSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678088; c=relaxed/simple; bh=CJkyw4Pe6fR3XV4v8fZkKyySghrcwh8OHib7UMXEgUQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WGtdrLYO/KfH+DJhbsTMFTQXRkWpWeE1porlG1/BASA+CaYPWNkCLr8lSz3b3GxeEkAuqq1FO9LI3fhvHnwHNAwezAXRb9A0BvPQ3hkrLIztLOVzK0BfksERnbm2wMa/uWqqUVTgXE5fU8OEr0Q6iiElErPI7k2+GisZJV45yAI= 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.32 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.163]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4X0yVf5Dq0z1xwtx; Sat, 7 Sep 2024 10:59:22 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id A8586180041; Sat, 7 Sep 2024 11:01:24 +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:23 +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:10:03 +0800 Message-ID: <20240907031009.3591057-6-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 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:10:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 826360 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (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 EA3B733991; Sat, 7 Sep 2024 03:01:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678092; cv=none; b=LTLKheCVPFkz+zM50wkvvaOX6zeSbFVfNIWpBoLGa7ycWOrpuA3ybHHrWZVRzsmJqTE48tblKNmw1T6Tr+VFj+H7IyHebj2fpH3EgHidIgllIdLfw/y/luprSc4oxCoG73hbG7NCuV5mq8QjibJYKyXGlMDbJjEsXbs2f+uqL6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678092; 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=i77sv+WgKTigSRtVy2SAYirwrYoWqvJzItBcxuPvkvZxlo/npxK+DbXGXa+iVe3xwcsFJD3vJWqWI2wIKf92TruqOATKxNoaXuwiURZOZ7yyLU6R9ND/rlKONz7xEJrBxev7l+z2XdcBlrpRFEBbkQi5xpwZ0iMRytZRTz+qfio= 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.188 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 szxga02-in.huawei.com (SkyGuard) with ESMTP id 4X0yVp5msjzpVXD; Sat, 7 Sep 2024 10:59:30 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 7BCF51800CF; Sat, 7 Sep 2024 11:01:27 +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:26 +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:10:06 +0800 Message-ID: <20240907031009.3591057-9-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 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); }