From: Zijie Zhao <zzjas98@gmail.com>
To: bhelgaas@google.com
Cc: linux-pci@vger.kernel.org, chenyuan0y@gmail.com
Subject: [drivers/pci] Possible memleak in pci_bus_set_aer_ops
Date: Wed, 13 Mar 2024 21:20:16 -0500 [thread overview]
Message-ID: <ZfJe4GZGpEQq7WIa@zijie-lab> (raw)
Dear PCI Developers,
We are curious whether the function `pci_bus_set_aer_ops` might have a memory leak.
The function is https://elixir.bootlin.com/linux/v6.8/source/drivers/pci/pcie/aer_inject.c#L297
and the relevant code is
```
static int pci_bus_set_aer_ops(struct pci_bus *bus)
{
struct pci_ops *ops;
struct pci_bus_ops *bus_ops;
unsigned long flags;
bus_ops = kmalloc(sizeof(*bus_ops), GFP_KERNEL);
if (!bus_ops)
return -ENOMEM;
ops = pci_bus_set_ops(bus, &aer_inj_pci_ops);
spin_lock_irqsave(&inject_lock, flags);
if (ops == &aer_inj_pci_ops)
goto out;
pci_bus_ops_init(bus_ops, bus, ops);
list_add(&bus_ops->list, &pci_bus_ops_list);
bus_ops = NULL;
out:
spin_unlock_irqrestore(&inject_lock, flags);
kfree(bus_ops);
return 0;
}
```
Here if the goto statement does not jump to `out`, the `bus_ops` will be assigned with `NULL` and then `kfree(bus_ops)` will not free the allocated memory.
Please kindly correct us if we missed any key information. Looking forward to your response!
Best,
Zijie
next reply other threads:[~2024-03-14 2:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-14 2:20 Zijie Zhao [this message]
2024-03-14 2:40 ` [drivers/pci] Possible memleak in pci_bus_set_aer_ops Kuppuswamy Sathyanarayanan
2024-03-14 6:19 ` [PATCH] fix memory leak " Zijie Zhao
2024-03-14 6:45 ` [drivers/pci] Possible memleak " Kuppuswamy Sathyanarayanan
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=ZfJe4GZGpEQq7WIa@zijie-lab \
--to=zzjas98@gmail.com \
--cc=bhelgaas@google.com \
--cc=chenyuan0y@gmail.com \
--cc=linux-pci@vger.kernel.org \
/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