lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230516051659.22194-1-xyzeng@stu.xidian.edu.cn>
Date:   Tue, 16 May 2023 13:16:59 +0800
From:   Xiangyi Zeng <xyzeng@....xidian.edu.cn>
To:     Lorenzo Pieralisi <lpieralisi@...nel.org>,
        Krzysztof WilczyƄski <kw@...ux.com>,
        Rob Herring <robh@...nel.org>,
        Bjorn Helgaas <bhelgaas@...gle.com>,
        Kishon Vijay Abraham I <kishon@...com>
Cc:     hust-os-kernel-patches@...glegroups.com,
        Xiangyi Zeng <xyzeng@....xidian.edu.cn>,
        Dongliang Mu <dzm91@...t.edu.cn>, linux-pci@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: [PATCH] PCI: dwc: keystone: Free IRQ in `ks_pcie_remove` and the error handling section of `ks_pcie_probe`

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 <xyzeng@....xidian.edu.cn>
Reviewed-by: Dongliang Mu <dzm91@...t.edu.cn>
---
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;
 }
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ