thunderbolt: Switch to use acpi_bus_get_primary_device()

Replace acpi_get_first_physical_node() that is slated for removal
with acpi_bus_get_primary_device() that takes a reference to the
device it is about to return.

This addresses a potential use-after-free that may occur if the
device returned by acpi_get_first_physical_node() is removed right
after dropping its ACPI companion's physical_node_lock in that
function.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Link: https://patch.msgid.link/1941270.atdPhlSkOF@rafael.j.wysocki
This commit is contained in:
Rafael J. Wysocki 2026-09-21 21:51:06 +02:00
parent 7a4c8ddba1
commit 37a78048d6

View File

@ -17,8 +17,8 @@ static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data,
struct acpi_device *adev = acpi_fetch_acpi_dev(handle);
struct fwnode_handle *fwnode;
struct tb_nhi *nhi = data;
struct device *dev = NULL;
struct pci_dev *pdev;
struct device *dev;
if (!adev)
return AE_OK;
@ -37,7 +37,7 @@ static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data,
* USB3 ports might not even have a physical device yet if xHCI driver
* isn't bound yet.
*/
dev = acpi_get_first_physical_node(adev);
dev = acpi_bus_get_primary_device(adev);
if (!dev || !dev_is_pci(dev))
goto out_put;
@ -74,6 +74,7 @@ static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data,
}
out_put:
put_device(dev);
fwnode_handle_put(fwnode);
return AE_OK;
}