From patchwork Sat Aug 31 02:13: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: 13785890 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8D2CCD1288 for ; Sat, 31 Aug 2024 02:09:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EwzggWyhvHFOIHzrdUlRc7ZabfpZjyfrJFwP2w14L3w=; b=3LzE/ZbKg+ZGtMMpHDlGUaAfzG 8PWEoDOHoAkzyrqXJaWMg9MxheJYJwwjcUxZl/oFxD+q1EsOuxJT8oEo5GZH3Vh1Pv9SKUsyUhX5R EfzZsfYAC9oGfDPyMvTufW3b7PU9XD5YMIdic0h1V/KAnfXXOwxZ0cb6GcPezClupVEL1KNbCTVAo zQfxqlvnURlxYYBcsHXGGcUQnISwOvpG6XIpjD4BQiJrXpP/e2ptL/cR3U0R6IQFvKiqyX6uHfRSy iZC3BiK+MJwsTX3A7Q3AkFGHFEGRodPfRwsmA7teKWGXekmItPmHVJJU3dfknOlGTpJ5142ibehsV aahJbSRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1skDXx-00000008INh-066T; Sat, 31 Aug 2024 02:09:01 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1skDUX-00000008HfT-2jTN; Sat, 31 Aug 2024 02:05:31 +0000 Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4WwdbD1D8kz1xwXg; Sat, 31 Aug 2024 10:03:20 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id F1D26140133; Sat, 31 Aug 2024 10:05:18 +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, 31 Aug 2024 10:05:17 +0800 From: Li Zetao To: , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , Subject: [PATCH net-next 01/12] net: dsa: bcm_sf2: Convert using devm_clk_get_optional_enabled() in bcm_sf2_sw_probe() Date: Sat, 31 Aug 2024 10:13:23 +0800 Message-ID: <20240831021334.1907921-2-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240831021334.1907921-1-lizetao1@huawei.com> References: <20240831021334.1907921-1-lizetao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemd500012.china.huawei.com (7.221.188.25) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240830_190530_287565_60CEF34F X-CRM114-Status: GOOD ( 11.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Signed-off-by: Li Zetao Acked-by: Florian Fainelli --- 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); }