public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
* [drivers/pci] Possible memleak in pci_bus_set_aer_ops
@ 2024-03-14  2:20 Zijie Zhao
  2024-03-14  2:40 ` Kuppuswamy Sathyanarayanan
  0 siblings, 1 reply; 4+ messages in thread
From: Zijie Zhao @ 2024-03-14  2:20 UTC (permalink / raw)
  To: bhelgaas; +Cc: linux-pci, chenyuan0y

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-14  6:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-14  2:20 [drivers/pci] Possible memleak in pci_bus_set_aer_ops Zijie Zhao
2024-03-14  2:40 ` Kuppuswamy Sathyanarayanan
2024-03-14  6:19   ` [PATCH] fix memory leak " Zijie Zhao
2024-03-14  6:45   ` [drivers/pci] Possible memleak " Kuppuswamy Sathyanarayanan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox