From: Zijun Hu <zijun_hu@icloud.com>
To: Bjorn Helgaas <bhelgaas@google.com>,
Rob Herring <robh@kernel.org>, Lizhi Hou <lizhi.hou@amd.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Zijun Hu <zijun_hu@icloud.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Zijun Hu <quic_zijuhu@quicinc.com>,
Zijun Hu <zijun.hu@oss.qualcomm.com>,
stable@vger.kernel.org
Subject: [PATCH v2 2/2] PCI: of: Fix OF device node refcount leakages in of_pci_prop_intr_map()
Date: Mon, 23 Jun 2025 21:17:39 +0800 [thread overview]
Message-ID: <20250623-fix_of_pci-v2-2-5bbb65190d47@oss.qualcomm.com> (raw)
In-Reply-To: <20250623-fix_of_pci-v2-0-5bbb65190d47@oss.qualcomm.com>
From: Zijun Hu <zijun.hu@oss.qualcomm.com>
Successful of_irq_parse_raw() invocation will increase refcount
of OF device node @out_irq[].np, but of_pci_prop_intr_map() does
not decrease the refcount before return, so cause @out_irq[].np
refcount leakages.
Fix by putting @out_irq[].np refcount before return.
Fixes: 407d1a51921e ("PCI: Create device tree node for bridge")
Cc: Rob Herring (Arm) <robh@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com>
---
drivers/pci/of_property.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c
index 506fcd5071139e0c11130f4c36f5082ed9789efb..4250a78fafbec4c29af124d7ba5ece7b0b785fb3 100644
--- a/drivers/pci/of_property.c
+++ b/drivers/pci/of_property.c
@@ -258,12 +258,16 @@ static int of_pci_prop_intr_map(struct pci_dev *pdev, struct of_changeset *ocs,
* Parsing interrupt failed for all pins. In this case, it does not
* need to generate interrupt-map property.
*/
- if (!map_sz)
- return 0;
+ if (!map_sz) {
+ ret = 0;
+ goto out_put_nodes;
+ }
int_map = kcalloc(map_sz, sizeof(u32), GFP_KERNEL);
- if (!int_map)
- return -ENOMEM;
+ if (!int_map) {
+ ret = -ENOMEM;
+ goto out_put_nodes;
+ }
mapp = int_map;
list_for_each_entry(child, &pdev->subordinate->devices, bus_list) {
@@ -305,14 +309,12 @@ static int of_pci_prop_intr_map(struct pci_dev *pdev, struct of_changeset *ocs,
ret = of_changeset_add_prop_u32_array(ocs, np, "interrupt-map-mask",
int_map_mask,
ARRAY_SIZE(int_map_mask));
- if (ret)
- goto failed;
-
- kfree(int_map);
- return 0;
failed:
kfree(int_map);
+out_put_nodes:
+ for (i = 0; i < OF_PCI_MAX_INT_PIN; i++)
+ of_node_put(out_irq[i].np);
return ret;
}
--
2.34.1
prev parent reply other threads:[~2025-06-23 13:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-23 13:17 [PATCH v2 0/2] PCI: of: Fix OF device node refcount leakages Zijun Hu
2025-06-23 13:17 ` [PATCH v2 1/2] PCI: of: Fix OF device node refcount leakage in API of_irq_parse_and_map_pci() Zijun Hu
2025-06-23 13:17 ` Zijun Hu [this message]
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=20250623-fix_of_pci-v2-2-5bbb65190d47@oss.qualcomm.com \
--to=zijun_hu@icloud.com \
--cc=bhelgaas@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lizhi.hou@amd.com \
--cc=quic_zijuhu@quicinc.com \
--cc=robh@kernel.org \
--cc=stable@vger.kernel.org \
--cc=zijun.hu@oss.qualcomm.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
all inboxes | Powered by JetHome®