Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thunderbolt: ACPI: Replace tb_acpi_find_port() with acpi_find_child_by_adr()

Use acpi_find_child_by_adr() to find the child matching a given bus
address instead of tb_acpi_find_port() that walks the list of children
of an ACPI device directly for this purpose and drop the latter.

Apart from simplifying the code, this will help to eliminate the
children list head from struct acpi_device as it is redundant and it
is used in questionable ways in some places (in particular, locking is
needed for walking the list pointed to it safely, but it is often
missing).

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

+8 -23
+8 -23
drivers/thunderbolt/acpi.c
··· 301 301 return tb_is_switch(dev) || tb_is_usb4_port_device(dev); 302 302 } 303 303 304 - static struct acpi_device *tb_acpi_find_port(struct acpi_device *adev, 305 - const struct tb_port *port) 306 - { 307 - struct acpi_device *port_adev; 308 - 309 - if (!adev) 310 - return NULL; 311 - 312 - /* 313 - * Device routers exists under the downstream facing USB4 port 314 - * of the parent router. Their _ADR is always 0. 315 - */ 316 - list_for_each_entry(port_adev, &adev->children, node) { 317 - if (acpi_device_adr(port_adev) == port->port) 318 - return port_adev; 319 - } 320 - 321 - return NULL; 322 - } 323 - 324 304 static struct acpi_device *tb_acpi_switch_find_companion(struct tb_switch *sw) 325 305 { 326 306 struct acpi_device *adev = NULL; 327 307 struct tb_switch *parent_sw; 328 308 309 + /* 310 + * Device routers exists under the downstream facing USB4 port 311 + * of the parent router. Their _ADR is always 0. 312 + */ 329 313 parent_sw = tb_switch_parent(sw); 330 314 if (parent_sw) { 331 315 struct tb_port *port = tb_port_at(tb_route(sw), parent_sw); 332 316 struct acpi_device *port_adev; 333 317 334 - port_adev = tb_acpi_find_port(ACPI_COMPANION(&parent_sw->dev), port); 318 + port_adev = acpi_find_child_by_adr(ACPI_COMPANION(&parent_sw->dev), 319 + port->port); 335 320 if (port_adev) 336 321 adev = acpi_find_child_device(port_adev, 0, false); 337 322 } else { ··· 349 364 if (tb_is_switch(dev)) 350 365 return tb_acpi_switch_find_companion(tb_to_switch(dev)); 351 366 else if (tb_is_usb4_port_device(dev)) 352 - return tb_acpi_find_port(ACPI_COMPANION(dev->parent), 353 - tb_to_usb4_port_device(dev)->port); 367 + return acpi_find_child_by_adr(ACPI_COMPANION(dev->parent), 368 + tb_to_usb4_port_device(dev)->port->port); 354 369 return NULL; 355 370 } 356 371