From nobody Wed Dec 17 00:33:15 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E11FC77B78 for ; Sat, 22 Apr 2023 07:48:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229565AbjDVHsk (ORCPT ); Sat, 22 Apr 2023 03:48:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjDVHsi (ORCPT ); Sat, 22 Apr 2023 03:48:38 -0400 Received: from hust.edu.cn (unknown [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFD211BDD; Sat, 22 Apr 2023 00:48:36 -0700 (PDT) Received: from amy-vm.localdomain ([10.12.183.232]) (user=yejunyan@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 33M7iZgr022988-33M7iZgs022988 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Sat, 22 Apr 2023 15:44:49 +0800 From: Junyan Ye To: Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , Wei Yongjun , Linus Walleij , Andrew Murray Cc: hust-os-kernel-patches@googlegroups.com, Junyan Ye , Dongliang Mu , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] pci: controller: pci-ftpci100: Release the clock resources Date: Sat, 22 Apr 2023 15:42:52 +0800 Message-Id: <20230422074254.14473-1-yejunyan@hust.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FEAS-AUTH-USER: yejunyan@hust.edu.cn Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. This includes notifying the system that the clock resource is no longer needed and revoking the prepared clock. 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 the warning by adding the clk_disable_unprepare function before returning the error message. 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 Hos= t Bridge driver") Fixes: f1e8bd21e39e ("PCI: faraday: Convert IRQ masking to raw PCI config a= ccessors") Signed-off-by: Junyan Ye Reviewed-by: Dongliang Mu --- This issue is found by static analyzer. drivers/pci/controller/pci-ftpci100.c | 31 +++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller= /pci-ftpci100.c index ecd3009df586..ca3ba377b3dd 100644 --- a/drivers/pci/controller/pci-ftpci100.c +++ b/drivers/pci/controller/pci-ftpci100.c @@ -438,17 +438,21 @@ static int faraday_pci_probe(struct platform_device *= pdev) return ret; } p->bus_clk =3D devm_clk_get(dev, "PCICLK"); - if (IS_ERR(p->bus_clk)) - return PTR_ERR(p->bus_clk); + if (IS_ERR(p->bus_clk)) { + ret =3D PTR_ERR(p->bus_clk); + goto err_release_clk; + } ret =3D clk_prepare_enable(p->bus_clk); if (ret) { dev_err(dev, "could not prepare PCICLK\n"); - return ret; + goto err_release_clk; } =20 p->base =3D devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(p->base)) - return PTR_ERR(p->base); + if (IS_ERR(p->base)) { + ret =3D PTR_ERR(p->base); + goto err_release_p_bus_clk; + } =20 win =3D resource_list_first_type(&host->windows, IORESOURCE_IO); if (win) { @@ -459,7 +463,8 @@ static int faraday_pci_probe(struct platform_device *pd= ev) writel(val, p->base + FTPCI_IOSIZE); } else { dev_err(dev, "illegal IO mem size\n"); - return -EINVAL; + ret =3D -EINVAL; + goto err_release_p_bus_clk; } } =20 @@ -475,7 +480,7 @@ static int faraday_pci_probe(struct platform_device *pd= ev) ret =3D faraday_pci_setup_cascaded_irq(p); if (ret) { dev_err(dev, "failed to setup cascaded IRQ\n"); - return ret; + goto err_release_p_bus_clk; } } =20 @@ -509,12 +514,12 @@ static int faraday_pci_probe(struct platform_device *= pdev) =20 ret =3D faraday_pci_parse_map_dma_ranges(p); if (ret) - return ret; + goto err_release_p_bus_clk; =20 ret =3D pci_scan_root_bus_bridge(host); if (ret) { dev_err(dev, "failed to scan host: %d\n", ret); - return ret; + goto err_release_p_bus_clk; } p->bus =3D host->bus; p->bus->max_bus_speed =3D max_bus_speed; @@ -524,6 +529,14 @@ static int faraday_pci_probe(struct platform_device *p= dev) pci_bus_add_devices(p->bus); =20 return 0; + +err_release_p_bus_clk: + clk_disable_unprepare(p->bus_clk); + +err_release_clk: + clk_disable_unprepare(clk); + + return ret; } =20 /* --=20 2.25.1