From: Wentao Guan <guanwentao@uniontech.com>
To: henhuacai@kernel.org, kernel@xen0n.name, loongarch@lists.linux.dev
Cc: linux-kernel@vger.kernel.org,
Wentao Guan <guanwentao@uniontech.com>,
Wangyuli <wangyuli@uniontech.com>
Subject: [PATCH] Loongarch64: pci: fix memleak in pci_acpi_scan_root
Date: Sat, 31 Aug 2024 13:21:57 +0800 [thread overview]
Message-ID: <20240831052157.13532-1-guanwentao@uniontech.com> (raw)
Add kfree(root_ops) in this case to avoid memleak root_ops,
leaks when pci_find_bus() != 0.
Also delay assign root_ops when used for making code read clean.
Found by code review
Signed-off-by: Wangyuli <wangyuli@uniontech.com>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
---
arch/loongarch/pci/acpi.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/loongarch/pci/acpi.c b/arch/loongarch/pci/acpi.c
index 3eb61b8cd5e3..7f3539f5fa23 100644
--- a/arch/loongarch/pci/acpi.c
+++ b/arch/loongarch/pci/acpi.c
@@ -219,17 +219,18 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
return NULL;
}
- root_ops->release_info = acpi_release_root_info;
- root_ops->prepare_resources = acpi_prepare_root_resources;
- root_ops->pci_ops = (struct pci_ops *)&info->cfg->ops->pci_ops;
-
bus = pci_find_bus(domain, busnum);
if (bus) {
memcpy(bus->sysdata, info->cfg, sizeof(struct pci_config_window));
kfree(info);
+ kfree(root_ops);
} else {
struct pci_bus *child;
+ root_ops->release_info = acpi_release_root_info;
+ root_ops->prepare_resources = acpi_prepare_root_resources;
+ root_ops->pci_ops = (struct pci_ops *)&info->cfg->ops->pci_ops;
+
bus = acpi_pci_root_create(root, root_ops,
&info->common, info->cfg);
if (!bus) {
--
2.20.1
next reply other threads:[~2024-08-31 5:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-31 5:21 Wentao Guan [this message]
2024-08-31 7:18 ` Huacai Chen
2024-08-31 7:30 ` Wentao Guan
2024-08-31 8:35 ` Wentao Guan
2024-08-31 12:37 ` Huacai Chen
2024-08-31 7:40 ` WangYuli
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=20240831052157.13532-1-guanwentao@uniontech.com \
--to=guanwentao@uniontech.com \
--cc=henhuacai@kernel.org \
--cc=kernel@xen0n.name \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=wangyuli@uniontech.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®