From patchwork Tue May 16 05:16:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5pu+56Wl57+8?= X-Patchwork-Id: 13242520 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 50E82C77B7F for ; Tue, 16 May 2023 05:18:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbjEPFSB (ORCPT ); Tue, 16 May 2023 01:18:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbjEPFSA (ORCPT ); Tue, 16 May 2023 01:18:00 -0400 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net (zg8tmtyylji0my4xnjqumte4.icoremail.net [162.243.164.118]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A878A2119; Mon, 15 May 2023 22:17:56 -0700 (PDT) Received: from wings-Z3-Air-S-Series-GK5MR0O.. (unknown [113.200.174.9]) by sr0414.icoremail.net (Coremail) with SMTP id AQAAfwB3YyCaEWNkWFlrAA--.3787S4; Tue, 16 May 2023 13:16:11 +0800 (CST) From: Xiangyi Zeng To: Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Rob Herring , Bjorn Helgaas , Kishon Vijay Abraham I Cc: hust-os-kernel-patches@googlegroups.com, Xiangyi Zeng , Dongliang Mu , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] PCI: dwc: keystone: Free IRQ in `ks_pcie_remove` and the error handling section of `ks_pcie_probe` Date: Tue, 16 May 2023 13:16:59 +0800 Message-Id: <20230516051659.22194-1-xyzeng@stu.xidian.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JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxh VjvjDU0xZFpf9x0JUP5rcUUUUU= X-CM-SenderInfo: p012v0vj6v33wo0lvxldqovvfxof0/ Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Smatch complains that: drivers/pci/controller/dwc/pci-keystone.c:1303 ks_pcie_probe() warn: 'irq' from request_irq() not released on lines: 1183,1187,1303. "ks-pcie-error-irq" was requested in the `ks_pcie_probe` function, but was not freed neither in the error handling part of `ks_pcie_probe` nor in the `ks_pcie_remove` function. Fix this by adding `free_irq` in `ks_pcie_remove` and in a new error handling label `err_alloc` after `err_link` in `ks_pcie_probe`. In `ks_pcie_probe`, if `phy` or `link` memory allocation fails, we will fall to `err_alloc`. If any other error occurs that leads to `err_get_sync` or `err_link`, we end up going to `err_alloc`. Fixes: 0790eb175ee0 ("PCI: keystone: Cleanup error_irq configuration") Signed-off-by: Xiangyi Zeng Reviewed-by: Dongliang Mu --- This patch is tested with compilation and passed Smatch. --- drivers/pci/controller/dwc/pci-keystone.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c index 78818853af9e..f321bc2e8026 100644 --- a/drivers/pci/controller/dwc/pci-keystone.c +++ b/drivers/pci/controller/dwc/pci-keystone.c @@ -1179,12 +1179,16 @@ static int __init ks_pcie_probe(struct platform_device *pdev) num_lanes = 1; phy = devm_kzalloc(dev, sizeof(*phy) * num_lanes, GFP_KERNEL); - if (!phy) - return -ENOMEM; + if (!phy) { + ret = -ENOMEM; + goto err_alloc; + } link = devm_kzalloc(dev, sizeof(*link) * num_lanes, GFP_KERNEL); - if (!link) - return -ENOMEM; + if (!link) { + ret = -ENOMEM; + goto err_alloc; + } for (i = 0; i < num_lanes; i++) { snprintf(name, sizeof(name), "pcie-phy%d", i); @@ -1300,6 +1304,9 @@ static int __init ks_pcie_probe(struct platform_device *pdev) while (--i >= 0 && link[i]) device_link_del(link[i]); +err_alloc: + free_irq(irq, ks_pcie); + return ret; } @@ -1309,12 +1316,14 @@ static int __exit ks_pcie_remove(struct platform_device *pdev) struct device_link **link = ks_pcie->link; int num_lanes = ks_pcie->num_lanes; struct device *dev = &pdev->dev; + int irq = platform_get_irq(pdev, 0); pm_runtime_put(dev); pm_runtime_disable(dev); ks_pcie_disable_phy(ks_pcie); while (num_lanes--) device_link_del(link[num_lanes]); + free_irq(irq, ks_pcie); return 0; }