From patchwork Sat Sep 7 03:19:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 13794993 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 BC5C738F83; Sat, 7 Sep 2024 03:10:40 +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=1725678642; cv=none; b=Jbs9KMQ6FkiD2Meqm22xRJO3nlzRYyzmgiSoRE85TlFU0yx5jqFbWEzFZD4bvHNLdQjXE4YW4j1tRKo+vB4rMhcmVWFyd+O2YY9p1QU97UC/GFHUyxDRAkNEth2dcHbzpPyImt8KQX/ZvY74hcEJPSdk5w6i9nTAmqAAni2DNvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725678642; c=relaxed/simple; bh=rtbaTRX0bb9wsX/8CJDV0DlVPBZLSH3Yn4d9LBq7zHQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qlOttMY1ZPUW4It8kmGXjYdiGX0EJCzmag7q04zOPDxeRVZ1R4jpKRy2Ow7UFCfrvo1+jiuhTM6UK3C6WSQlVqBcIv6n88F/YCiGlLDfLYEvUwCBfdSXQeHH0dneM3r/3AmOvPiUVoTXI36BQ2vDKQgfLRnnqYiPYdKrkfSTsUQ= 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.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4X0ydt3hkwz20nY9; Sat, 7 Sep 2024 11:05:38 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id 8298B1400CF; Sat, 7 Sep 2024 11:10:38 +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:37 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH net-next v2 01/10] net: dsa: bcm_sf2: Convert using devm_clk_get_optional_enabled() in bcm_sf2_sw_probe() Date: Sat, 7 Sep 2024 11:19:17 +0800 Message-ID: <20240907031926.3591353-2-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_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, drop the out_clk_mdiv and out_clk labels, and the original error process can be returned directly. Acked-by: Florian Fainelli Signed-off-by: Li Zetao --- drivers/net/dsa/bcm_sf2.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c index 0e663ec0c12a..96c0fdb56601 100644 --- a/drivers/net/dsa/bcm_sf2.c +++ b/drivers/net/dsa/bcm_sf2.c @@ -1453,28 +1453,18 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev) base++; } - priv->clk = devm_clk_get_optional(&pdev->dev, "sw_switch"); + priv->clk = devm_clk_get_optional_enabled(&pdev->dev, "sw_switch"); if (IS_ERR(priv->clk)) return PTR_ERR(priv->clk); - ret = clk_prepare_enable(priv->clk); - if (ret) - return ret; - - priv->clk_mdiv = devm_clk_get_optional(&pdev->dev, "sw_switch_mdiv"); - if (IS_ERR(priv->clk_mdiv)) { - ret = PTR_ERR(priv->clk_mdiv); - goto out_clk; - } - - ret = clk_prepare_enable(priv->clk_mdiv); - if (ret) - goto out_clk; + priv->clk_mdiv = devm_clk_get_optional_enabled(&pdev->dev, "sw_switch_mdiv"); + if (IS_ERR(priv->clk_mdiv)) + return PTR_ERR(priv->clk_mdiv); ret = bcm_sf2_sw_rst(priv); if (ret) { pr_err("unable to software reset switch: %d\n", ret); - goto out_clk_mdiv; + return ret; } bcm_sf2_crossbar_setup(priv); @@ -1484,7 +1474,7 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev) ret = bcm_sf2_mdio_register(ds); if (ret) { pr_err("failed to register MDIO bus\n"); - goto out_clk_mdiv; + return ret; } bcm_sf2_gphy_enable_set(priv->dev->ds, false); @@ -1551,10 +1541,6 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev) out_mdio: bcm_sf2_mdio_unregister(priv); -out_clk_mdiv: - clk_disable_unprepare(priv->clk_mdiv); -out_clk: - clk_disable_unprepare(priv->clk); return ret; } @@ -1571,8 +1557,6 @@ static void bcm_sf2_sw_remove(struct platform_device *pdev) dsa_unregister_switch(priv->dev->ds); bcm_sf2_cfp_exit(priv->dev->ds); bcm_sf2_mdio_unregister(priv); - clk_disable_unprepare(priv->clk_mdiv); - clk_disable_unprepare(priv->clk); if (priv->type == BCM7278_DEVICE_ID) reset_control_assert(priv->rcdev); } 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: 13794956 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);