From patchwork Sun Aug 27 13:41:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 13367284 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 205C8C83F11 for ; Sun, 27 Aug 2023 13:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=v5JoaNv+F6qfelkLQsDCUCUXKfNWA+E5mcsKJo00bhM=; b=y/7X9ft5AOWuHI 0j87qeljy+ure0PIaESKPeZJE5guXYQgv8babh8fD6RxvR4E7S/uHrHPNE36KInEqE9fCqq5qvvvQ sSYPXQiyGls6M6CQe6blG2dL0fKUxvnQL++IZZNQ/ft5rqQPQO7QFXpZycrvfa7NW1HtVlbw5i6o4 uCpPEGQstzcNRSrk/NSm2dMI3+/WavDnEk4JF8AxXi6tzKIjDNFM4NS0VgpVD7araTxELyh29ZSoo cdZJn0LZXyE0vkIWXAPnYeVBaNGMMK259sS2nzL7XEryseqXb+IHdtdcIlT1cIljcG7xVw88EBmy4 La6D2IU1OODCW09S9QrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qaGDD-00880Y-0x; Sun, 27 Aug 2023 13:53:55 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qaGD9-0087z6-0l for linux-arm-kernel@lists.infradead.org; Sun, 27 Aug 2023 13:53:52 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AA02961A73; Sun, 27 Aug 2023 13:53:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 888A8C433CA; Sun, 27 Aug 2023 13:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693144430; bh=2bvndDeKIa1am5zfMWn8oY7XCThEt0L62331HK8Om4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HpsKqOzZidGunvuUuKkUzRb3nxHPc6vpjly9uclBMCkpdnASEMbh1YnJNIzuIbDs7 YwPRHtAGPCt0WsivqZnsO/4j80+ouaxH2miPPoKo+rWIj31qs9kXie4PLbSMlmHwCP MM1fG7LvhxkHPtPod8gs8W8m93I6nxiQdniWVkYsm3BfU6+paCY7ZtlP2O6vGb0Icc sjJb8ffbiBVdGNnWamtfou93biN5+pYsY+gWElJtkrWDnRLG18sNjH0gg3MaBiYRyu njcB1BQ9+akEOgCe7fu1pN/JXOGheQfy7Wxjb6nqDwuVHu/6SiVGMcZ7vtfZg4rf5f wZqSpIl1vo4+A== From: Jisheng Zhang To: Emil Renner Berthing , Samin Guo , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin Cc: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/2] net: stmmac: dwmac-starfive: improve error handling during probe Date: Sun, 27 Aug 2023 21:41:49 +0800 Message-Id: <20230827134150.2918-2-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230827134150.2918-1-jszhang@kernel.org> References: <20230827134150.2918-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230827_065351_360364_1E121D9C X-CRM114-Status: GOOD ( 14.22 ) 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 After stmmac_probe_config_dt() succeeds, when error happens later, stmmac_remove_config_dt() needs to be called for proper error handling. Signed-off-by: Jisheng Zhang --- .../ethernet/stmicro/stmmac/dwmac-starfive.c | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c index 892612564694..b68f42795eaa 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c @@ -111,18 +111,24 @@ static int starfive_dwmac_probe(struct platform_device *pdev) "dt configuration failed\n"); dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); - if (!dwmac) - return -ENOMEM; + if (!dwmac) { + err = -ENOMEM; + goto err_remove_config_dt; + } dwmac->clk_tx = devm_clk_get_enabled(&pdev->dev, "tx"); - if (IS_ERR(dwmac->clk_tx)) - return dev_err_probe(&pdev->dev, PTR_ERR(dwmac->clk_tx), - "error getting tx clock\n"); + if (IS_ERR(dwmac->clk_tx)) { + err = dev_err_probe(&pdev->dev, PTR_ERR(dwmac->clk_tx), + "error getting tx clock\n"); + goto err_remove_config_dt; + } clk_gtx = devm_clk_get_enabled(&pdev->dev, "gtx"); - if (IS_ERR(clk_gtx)) - return dev_err_probe(&pdev->dev, PTR_ERR(clk_gtx), - "error getting gtx clock\n"); + if (IS_ERR(clk_gtx)) { + err = dev_err_probe(&pdev->dev, PTR_ERR(clk_gtx), + "error getting gtx clock\n"); + goto err_remove_config_dt; + } /* Generally, the rgmii_tx clock is provided by the internal clock, * which needs to match the corresponding clock frequency according @@ -139,15 +145,17 @@ static int starfive_dwmac_probe(struct platform_device *pdev) err = starfive_dwmac_set_mode(plat_dat); if (err) - return err; + goto err_remove_config_dt; err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); - if (err) { - stmmac_remove_config_dt(pdev, plat_dat); - return err; - } + if (err) + goto err_remove_config_dt; return 0; + +err_remove_config_dt: + stmmac_remove_config_dt(pdev, plat_dat); + return err; } static const struct of_device_id starfive_dwmac_match[] = {