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

ACPI: utils: Introduce helper for _DEP list lookup

The ACPI LPSS driver and the Surface platform driver code use almost the
same code pattern for checking if one ACPI device is present in the list
returned by _DEP for another ACPI device.

To reduce the resulting code duplication, introduce a helper for that
called acpi_device_dep() and invoke it from both places.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>

+38 -54
+2 -27
drivers/acpi/acpi_lpss.c
··· 562 562 return bus_find_device(&pci_bus_type, NULL, &data, match_hid_uid); 563 563 } 564 564 565 - static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle) 566 - { 567 - struct acpi_handle_list dep_devices; 568 - bool ret = false; 569 - int i; 570 - 571 - if (!acpi_has_method(adev->handle, "_DEP")) 572 - return false; 573 - 574 - if (!acpi_evaluate_reference(adev->handle, "_DEP", NULL, &dep_devices)) { 575 - dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n"); 576 - return false; 577 - } 578 - 579 - for (i = 0; i < dep_devices.count; i++) { 580 - if (dep_devices.handles[i] == handle) { 581 - ret = true; 582 - break; 583 - } 584 - } 585 - 586 - acpi_handle_list_free(&dep_devices); 587 - return ret; 588 - } 589 - 590 565 static void acpi_lpss_link_consumer(struct device *dev1, 591 566 const struct lpss_device_links *link) 592 567 { ··· 572 597 return; 573 598 574 599 if ((link->dep_missing_ids && dmi_check_system(link->dep_missing_ids)) 575 - || acpi_lpss_dep(ACPI_COMPANION(dev2), ACPI_HANDLE(dev1))) 600 + || acpi_device_dep(ACPI_HANDLE(dev2), ACPI_HANDLE(dev1))) 576 601 device_link_add(dev2, dev1, link->flags); 577 602 578 603 put_device(dev2); ··· 588 613 return; 589 614 590 615 if ((link->dep_missing_ids && dmi_check_system(link->dep_missing_ids)) 591 - || acpi_lpss_dep(ACPI_COMPANION(dev1), ACPI_HANDLE(dev2))) 616 + || acpi_device_dep(ACPI_HANDLE(dev1), ACPI_HANDLE(dev2))) 592 617 device_link_add(dev1, dev2, link->flags); 593 618 594 619 put_device(dev2);
+34
drivers/acpi/utils.c
··· 450 450 } 451 451 EXPORT_SYMBOL_GPL(acpi_handle_list_free); 452 452 453 + /** 454 + * acpi_device_dep - Check ACPI device dependency 455 + * @target: ACPI handle of the target ACPI device. 456 + * @match: ACPI handle to look up in the target's _DEP list. 457 + * 458 + * Return true if @match is present in the list returned by _DEP for 459 + * @target or false otherwise. 460 + */ 461 + bool acpi_device_dep(acpi_handle target, acpi_handle match) 462 + { 463 + struct acpi_handle_list dep_devices; 464 + bool ret = false; 465 + int i; 466 + 467 + if (!acpi_has_method(target, "_DEP")) 468 + return false; 469 + 470 + if (!acpi_evaluate_reference(target, "_DEP", NULL, &dep_devices)) { 471 + acpi_handle_debug(target, "Failed to evaluate _DEP.\n"); 472 + return false; 473 + } 474 + 475 + for (i = 0; i < dep_devices.count; i++) { 476 + if (dep_devices.handles[i] == match) { 477 + ret = true; 478 + break; 479 + } 480 + } 481 + 482 + acpi_handle_list_free(&dep_devices); 483 + return ret; 484 + } 485 + EXPORT_SYMBOL_GPL(acpi_device_dep); 486 + 453 487 acpi_status 454 488 acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld) 455 489 {
+1 -27
drivers/platform/surface/surface_acpi_notify.c
··· 736 736 #define san_consumer_warn(dev, handle, fmt, ...) \ 737 737 san_consumer_printk(warn, dev, handle, fmt, ##__VA_ARGS__) 738 738 739 - static bool is_san_consumer(struct platform_device *pdev, acpi_handle handle) 740 - { 741 - struct acpi_handle_list dep_devices; 742 - acpi_handle supplier = ACPI_HANDLE(&pdev->dev); 743 - bool ret = false; 744 - int i; 745 - 746 - if (!acpi_has_method(handle, "_DEP")) 747 - return false; 748 - 749 - if (!acpi_evaluate_reference(handle, "_DEP", NULL, &dep_devices)) { 750 - san_consumer_dbg(&pdev->dev, handle, "failed to evaluate _DEP\n"); 751 - return false; 752 - } 753 - 754 - for (i = 0; i < dep_devices.count; i++) { 755 - if (dep_devices.handles[i] == supplier) { 756 - ret = true; 757 - break; 758 - } 759 - } 760 - 761 - acpi_handle_list_free(&dep_devices); 762 - return ret; 763 - } 764 - 765 739 static acpi_status san_consumer_setup(acpi_handle handle, u32 lvl, 766 740 void *context, void **rv) 767 741 { ··· 744 770 struct acpi_device *adev; 745 771 struct device_link *link; 746 772 747 - if (!is_san_consumer(pdev, handle)) 773 + if (!acpi_device_dep(handle, ACPI_HANDLE(&pdev->dev))) 748 774 return AE_OK; 749 775 750 776 /* Ignore ACPI devices that are not present. */
+1
include/acpi/acpi_bus.h
··· 33 33 void acpi_handle_list_replace(struct acpi_handle_list *dst, 34 34 struct acpi_handle_list *src); 35 35 void acpi_handle_list_free(struct acpi_handle_list *list); 36 + bool acpi_device_dep(acpi_handle target, acpi_handle match); 36 37 acpi_status 37 38 acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code, 38 39 struct acpi_buffer *status_buf);