git: f9a37065b694 - main - LinuxKPI: fix lkpi_pci_get_device() reference counting on device
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 13 Jul 2026 14:59:20 UTC
The branch main has been updated by bz:
URL: https://cgit.FreeBSD.org/src/commit/?id=f9a37065b6948831f62a33fd0c68c96985b01a41
commit f9a37065b6948831f62a33fd0c68c96985b01a41
Author: Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2026-06-01 04:58:00 +0000
Commit: Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-07-13 14:58:23 +0000
LinuxKPI: fix lkpi_pci_get_device() reference counting on device
In case we are passed an "odev" (a device to start the search from),
that device would have an extra reference. The best way to illustrate
this is to look at for_each_pci_dev(), which will return one device
after the other. Upon first return we return a pdev with a reference.
That pdev is then passed in as odev on the next call. If we do not
clear the reference it will be leaked.
Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Fixes: 910cf345d0ee9 ("LinuxKPI: pci: implement ...")
Reviewed by: dumbbell, emaste
Differential Revision: https://reviews.freebsd.org/D57428
---
sys/compat/linuxkpi/common/src/linux_pci.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c
index 477cb321ea9e..cdf7f00184ce 100644
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -308,8 +308,9 @@ linux_pci_find(device_t dev, const struct pci_device_id **idp)
struct pci_dev *
lkpi_pci_get_device(uint32_t vendor, uint32_t device, struct pci_dev *odev)
{
- struct pci_dev *pdev, *found;
+ struct pci_dev *pdev, *found, *odev0;
+ odev0 = odev;
found = NULL;
spin_lock(&pci_lock);
list_for_each_entry(pdev, &pci_devices, links) {
@@ -328,6 +329,7 @@ lkpi_pci_get_device(uint32_t vendor, uint32_t device, struct pci_dev *odev)
}
pci_dev_get(found);
spin_unlock(&pci_lock);
+ pci_dev_put(odev0);
return (found);
}