Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Junyan Ye <yejunyan@hust.edu.cn>
To: christophe.jaillet@wanadoo.fr,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Rob Herring" <robh@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Wei Yongjun" <weiyongjun1@huawei.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Andrew Murray" <amurray@thegoodpenguin.co.uk>
Cc: hust-os-kernel-patches@googlegroups.com,
	Junyan Ye <yejunyan@hust.edu.cn>,
	Dongliang Mu <dzm91@hust.edu.cn>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] pci: controller: pci-ftpci100: Release the clock resources
Date: Sun, 23 Apr 2023 13:32:07 +0800	[thread overview]
Message-ID: <20230423053208.2348-1-yejunyan@hust.edu.cn> (raw)

Smatch reported:
1. drivers/pci/controller/pci-ftpci100.c:526 faraday_pci_probe()
warn: 'clk' from clk_prepare_enable() not released on lines:
442,451,462,478,512,517.
2. drivers/pci/controller/pci-ftpci100.c:526 faraday_pci_probe()
warn: 'p->bus_clk' from clk_prepare_enable() not released on lines:
451,462,478,512,517.

The clock resource is obtained by the devm_clk_get function. The
clk_prepare_enable function then makes the clock resource ready for use,
notifying the system that the clock resource should be run. After that,
the clock resource should be released when it is no longer needed. The
corresponding function is clk_disable_unprepare. However, while doing
some error handling in the faraday_pci_probe function, the
clk_disable_unprepare function is not called to release the clk and
p->bus_clk resources.

Fix this warning by changing the devm_clk_get function to
devm_clk_get_enabled, which is equivalent to
devm_clk_get() + clk_prepare_enable(). And with the
devm_clk_get_enabled function, the clock will automatically be
disabled, unprepared and freed when the device is unbound from the bus.

Fixes: b3c433efb8a3 ("PCI: faraday: Fix wrong pointer passed to PTR_ERR()")
Fixes: 2eeb02b28579 ("PCI: faraday: Add clock handling")
Fixes: 783a862563f7 ("PCI: faraday: Use pci_parse_request_of_pci_ranges()")
Fixes: d3c68e0a7e34 ("PCI: faraday: Add Faraday Technology FTPCI100 PCI Host Bridge driver")
Fixes: f1e8bd21e39e ("PCI: faraday: Convert IRQ masking to raw PCI config accessors")
Signed-off-by: Junyan Ye <yejunyan@hust.edu.cn>
Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
---
v1 -> v2: Switch from clk_disable_unprepare() to devm_clk_get_enabled() to release the clock.
This issue is found by static analyzer.

 drivers/pci/controller/pci-ftpci100.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c
index ecd3009df586..6e7981d2ed5e 100644
--- a/drivers/pci/controller/pci-ftpci100.c
+++ b/drivers/pci/controller/pci-ftpci100.c
@@ -429,22 +429,12 @@ static int faraday_pci_probe(struct platform_device *pdev)
 	p->dev = dev;
 
 	/* Retrieve and enable optional clocks */
-	clk = devm_clk_get(dev, "PCLK");
+	clk = devm_clk_get_enabled(dev, "PCLK");
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
-	ret = clk_prepare_enable(clk);
-	if (ret) {
-		dev_err(dev, "could not prepare PCLK\n");
-		return ret;
-	}
-	p->bus_clk = devm_clk_get(dev, "PCICLK");
+	p->bus_clk = devm_clk_get_enabled(dev, "PCICLK");
 	if (IS_ERR(p->bus_clk))
 		return PTR_ERR(p->bus_clk);
-	ret = clk_prepare_enable(p->bus_clk);
-	if (ret) {
-		dev_err(dev, "could not prepare PCICLK\n");
-		return ret;
-	}
 
 	p->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(p->base))
-- 
2.25.1


             reply	other threads:[~2023-04-23  5:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-23  5:32 Junyan Ye [this message]
2023-04-26 20:44 ` [PATCH v2] pci: controller: pci-ftpci100: Release the clock resources Linus Walleij
2023-04-27 18:38 ` Bjorn Helgaas

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=20230423053208.2348-1-yejunyan@hust.edu.cn \
    --to=yejunyan@hust.edu.cn \
    --cc=amurray@thegoodpenguin.co.uk \
    --cc=bhelgaas@google.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=dzm91@hust.edu.cn \
    --cc=hust-os-kernel-patches@googlegroups.com \
    --cc=kw@linux.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=robh@kernel.org \
    --cc=weiyongjun1@huawei.com \
    /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