Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4157924rwr; Sat, 22 Apr 2023 22:47:12 -0700 (PDT) X-Google-Smtp-Source: AKy350Z2UWLtrU9GdjWnEOmp3lHZApOW4tFTbY+qxVgcjfEcuDJfMwQQjyE0U2sEEDx+oM/3BXWI X-Received: by 2002:a05:6a00:1951:b0:63d:3a18:49fd with SMTP id s17-20020a056a00195100b0063d3a1849fdmr10974579pfk.2.1682228832094; Sat, 22 Apr 2023 22:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682228832; cv=none; d=google.com; s=arc-20160816; b=GtaYhgQPpcft7+PaDuN4VZv7Cznq2Tc3LKD0lVCwC4kVlMJBxg2sgdnYNoP3V9d61y u/fAp9tt9x7xMCzbLG/SvT3YcboF9rofcE1XBml8N55iVeMWILpdTN33eoMNLt6SHW4n i93bL1Do21Pt3CJ2Dn/9a6Z5G5FfKZ65AQ0OFZN6QpMgh7+5qOM65cB5sA0ppVViOVHu gWKByu4WDDysu+iuKbaYX0UJ6lOAZ3PFAV2n/NUKUTlDaNroEnNTqfSEntFd04kEr8DL 9AQdpJ2LzvBD8mrbgU1Y8tBqkDJVT9dOiILfYv1RWrywjrnsNWKxATxmMYxULstxNMkY 2mbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=yhTBgbq0kmSFPgsS4r8kmFNMuUCWHZh77mtYcA0soWg=; b=a6Ab5xsjC3lJbhQO9IfhtmzsnCJIKQcEHYpmW+YbNH+BhUOugfxSqBZl5mCg2oBC9o 4kyGFolb/qmA2VzOdCYhiHYyvLPyzk8kt+LcX7MiwwUnQ+Xc5xvwpVEFugBgmy3Rh1J0 c92xAngQ26oN6EPgjc3g/1ODE1+4aomveiFk3kjJZlN29Uzr19PGI38QBObF6dpKBTB4 cROVBGsSEuL+oRHehmbHkyP2CymbSS5pSPMB3WMH+t7ijVIO/fZNIsbjFw5C1XgI9N1f ZHiQ7n6j5q32EUl92RK4DuX2WloslV4c55ArJvfcg7lAgfFgSmk1mnquQdgXpvU6xu5t QM/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9-20020a631d09000000b0051b53285341si8538559pgd.277.2023.04.22.22.47.00; Sat, 22 Apr 2023 22:47:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229966AbjDWFed (ORCPT + 99 others); Sun, 23 Apr 2023 01:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229516AbjDWFec (ORCPT ); Sun, 23 Apr 2023 01:34:32 -0400 Received: from hust.edu.cn (unknown [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5A371736; Sat, 22 Apr 2023 22:34:30 -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 33N5XPSO011752-33N5XPSP011752 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Sun, 23 Apr 2023 13:33:30 +0800 From: Junyan Ye To: christophe.jaillet@wanadoo.fr, 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 v2] pci: controller: pci-ftpci100: Release the clock resources Date: Sun, 23 Apr 2023 13:32:07 +0800 Message-Id: <20230423053208.2348-1-yejunyan@hust.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: yejunyan@hust.edu.cn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Dongliang Mu --- 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