From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
To: zzjas98@gmail.com, bhelgaas@google.com
Cc: linux-pci@vger.kernel.org, chenyuan0y@gmail.com
Subject: Re: [drivers/pci] Possible memleak in pci_bus_set_aer_ops
Date: Wed, 13 Mar 2024 19:40:09 -0700 [thread overview]
Message-ID: <518813f8-294f-461c-b0dc-e980893a9ebf@linux.intel.com> (raw)
In-Reply-To: <ZfJe4GZGpEQq7WIa@zijie-lab>
On 3/13/24 7:20 PM, Zijie Zhao wrote:
> 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!
I think it is a valid issue that needs to be fixed. If you would like, please send a patch to fix it.
>
> Best,
> Zijie
>
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
next prev parent reply other threads:[~2024-03-14 2:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-14 2:20 [drivers/pci] Possible memleak in pci_bus_set_aer_ops Zijie Zhao
2024-03-14 2:40 ` Kuppuswamy Sathyanarayanan [this message]
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=518813f8-294f-461c-b0dc-e980893a9ebf@linux.intel.com \
--to=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=chenyuan0y@gmail.com \
--cc=linux-pci@vger.kernel.org \
--cc=zzjas98@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.