Page MenuHomeFreeBSD

LinuxKPI: pci: fix two errors in lkpi_pci_get_device()
ClosedPublic

Authored by bz on May 4 2025, 10:03 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Oct 11, 5:31 AM
Unknown Object (File)
Thu, Oct 8, 7:16 PM
Unknown Object (File)
Wed, Oct 7, 3:30 AM
Unknown Object (File)
Tue, Oct 6, 4:04 PM
Unknown Object (File)
Sat, Sep 19, 2:59 AM
Unknown Object (File)
Sat, Sep 19, 2:58 AM
Unknown Object (File)
Sat, Sep 19, 2:30 AM
Unknown Object (File)
Wed, Sep 16, 9:53 PM
Subscribers

Details

Summary

On any result we need to acquire a reference. pci_dev_get() deals with
a NULL argument so we can simply pass what we "found" at the end.
This will avoid reference count problems.

If the iteration on the linux list in lkpi_pci_get_device() does
not find a match pdev will still be defined at the end of the
loop but not pointing to a valid pdev.
Store the found entry in a 2nd variable which otherwise will be NULL.
This will avoid random panics, usually in sysfs_remove_dir() when
the reference gets released.

Found during mt76 bringup.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Fixes: 8f61992d7cc11

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 63877
Build 60761: arc lint + arc unit