aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern A. Zeeb <bz@FreeBSD.org>2026-06-01 04:58:00 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2026-07-13 14:58:23 +0000
commitf9a37065b6948831f62a33fd0c68c96985b01a41 (patch)
tree7880fda4720e2c9d3b9706ff2b2328056f0fc121
parent058ce52660fb52ada41462d339fb1ce6aca48cf3 (diff)
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
-rw-r--r--sys/compat/linuxkpi/common/src/linux_pci.c4
1 files changed, 3 insertions, 1 deletions
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);
}