From: Simon Horman <horms@kernel.org>
To: Vitalii Mordan <mordan@ispras.ru>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>,
Jose Abreu <joabreu@synopsys.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org,
Fedor Pchelkin <pchelkin@ispras.ru>,
Alexey Khoroshilov <khoroshilov@ispras.ru>,
Vadim Mutilin <mutilin@ispras.ru>
Subject: Re: [PATCH net] stmmac: dwmac-intel-plat: fix call balance of tx_clk handling routines
Date: Thu, 3 Oct 2024 12:18:11 +0100 [thread overview]
Message-ID: <20241003111811.GJ1310185@kernel.org> (raw)
In-Reply-To: <20240930183715.2112075-1-mordan@ispras.ru>
On Mon, Sep 30, 2024 at 09:37:15PM +0300, Vitalii Mordan wrote:
> If the clock dwmac->tx_clk was not enabled in intel_eth_plat_probe,
> it should not be disabled in any path.
>
> Conversely, if it was enabled in intel_eth_plat_probe, it must be disabled
> in all error paths to ensure proper cleanup.
>
> Found by Linux Verification Center (linuxtesting.org) with Klever.
>
> Fixes: 9efc9b2b04c7 ("net: stmmac: Add dwmac-intel-plat for GBE driver")
> Signed-off-by: Vitalii Mordan <mordan@ispras.ru>
> ---
> .../ethernet/stmicro/stmmac/dwmac-intel-plat.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c
> index d68f0c4e7835..2a2893f2f2a8 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c
> @@ -108,7 +108,12 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
> if (IS_ERR(dwmac->tx_clk))
> return PTR_ERR(dwmac->tx_clk);
>
> - clk_prepare_enable(dwmac->tx_clk);
> + ret = clk_prepare_enable(dwmac->tx_clk);
> + if (ret) {
> + dev_err(&pdev->dev,
> + "Failed to enable tx_clk\n");
> + return ret;
> + }
>
> /* Check and configure TX clock rate */
> rate = clk_get_rate(dwmac->tx_clk);
> @@ -117,6 +122,7 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
> rate = dwmac->data->tx_clk_rate;
> ret = clk_set_rate(dwmac->tx_clk, rate);
> if (ret) {
> + clk_disable_unprepare(dwmac->tx_clk);
> dev_err(&pdev->dev,
> "Failed to set tx_clk\n");
> return ret;
Hi Vitalii,
I think that unwinding using a goto label would be more idiomatic here
and in the following changes to intel_eth_plat_probe().
> @@ -131,6 +137,8 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
> rate = dwmac->data->ptp_ref_clk_rate;
> ret = clk_set_rate(plat_dat->clk_ptp_ref, rate);
> if (ret) {
> + if (dwmac->data->tx_clk_en)
> + clk_disable_unprepare(dwmac->tx_clk);
> dev_err(&pdev->dev,
> "Failed to set clk_ptp_ref\n");
> return ret;
> @@ -150,7 +158,8 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
>
> ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
> if (ret) {
> - clk_disable_unprepare(dwmac->tx_clk);
> + if (dwmac->data->tx_clk_en)
> + clk_disable_unprepare(dwmac->tx_clk);
Smatch warns that dwmac->data may be NULL here.
> return ret;
> }
>
> @@ -162,7 +171,8 @@ static void intel_eth_plat_remove(struct platform_device *pdev)
> struct intel_dwmac *dwmac = get_stmmac_bsp_priv(&pdev->dev);
>
> stmmac_pltfr_remove(pdev);
> - clk_disable_unprepare(dwmac->tx_clk);
> + if (dwmac->data->tx_clk_en)
And I wonder if it can be NULL here too.
> + clk_disable_unprepare(dwmac->tx_clk);
> }
>
> static struct platform_driver intel_eth_plat_driver = {
> --
> 2.25.1
>
>
next prev parent reply other threads:[~2024-10-03 11:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-30 18:37 [PATCH net] stmmac: dwmac-intel-plat: fix call balance of tx_clk handling routines Vitalii Mordan
2024-10-03 11:18 ` Simon Horman [this message]
2024-10-03 12:55 ` Fedor Pchelkin
2024-10-03 14:35 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241003111811.GJ1310185@kernel.org \
--to=horms@kernel.org \
--cc=alexandre.torgue@foss.st.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=joabreu@synopsys.com \
--cc=khoroshilov@ispras.ru \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=lvc-project@linuxtesting.org \
--cc=mcoquelin.stm32@gmail.com \
--cc=mordan@ispras.ru \
--cc=mutilin@ispras.ru \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pchelkin@ispras.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).