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

PCI Hotplug: acpiphp: clean up list traversals

Using list_for_each_entry instead of list_for_each allows us to
enhance readability and minorly reduce some stack usage.

Signed-off-by: Alex Chiang <achiang@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>

authored by

Alex Chiang and committed by
Jesse Barnes
58c08628 204d49a5

+17 -41
+17 -41
drivers/pci/hotplug/acpiphp_glue.c
··· 309 309 /* find acpiphp_func from acpiphp_bridge */ 310 310 static struct acpiphp_func *acpiphp_bridge_handle_to_function(acpi_handle handle) 311 311 { 312 - struct list_head *node, *l; 313 312 struct acpiphp_bridge *bridge; 314 313 struct acpiphp_slot *slot; 315 314 struct acpiphp_func *func; 316 315 317 - list_for_each(node, &bridge_list) { 318 - bridge = list_entry(node, struct acpiphp_bridge, list); 316 + list_for_each_entry(bridge, &bridge_list, list) { 319 317 for (slot = bridge->slots; slot; slot = slot->next) { 320 - list_for_each(l, &slot->funcs) { 321 - func = list_entry(l, struct acpiphp_func, 322 - sibling); 318 + list_for_each_entry(func, &slot->funcs, sibling) { 323 319 if (func->handle == handle) 324 320 return func; 325 321 } ··· 489 493 490 494 static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) 491 495 { 492 - struct list_head *head; 493 - list_for_each(head, &bridge_list) { 494 - struct acpiphp_bridge *bridge = list_entry(head, 495 - struct acpiphp_bridge, list); 496 + struct acpiphp_bridge *bridge; 497 + 498 + list_for_each_entry(bridge, &bridge_list, list) 496 499 if (bridge->handle == handle) 497 500 return bridge; 498 - } 499 501 500 502 return NULL; 501 503 } 502 504 503 505 static void cleanup_bridge(struct acpiphp_bridge *bridge) 504 506 { 505 - struct list_head *list, *tmp; 506 - struct acpiphp_slot *slot; 507 + struct acpiphp_slot *slot, *next; 508 + struct acpiphp_func *func, *tmp; 507 509 acpi_status status; 508 510 acpi_handle handle = bridge->handle; 509 511 ··· 522 528 523 529 slot = bridge->slots; 524 530 while (slot) { 525 - struct acpiphp_slot *next = slot->next; 526 - list_for_each_safe (list, tmp, &slot->funcs) { 527 - struct acpiphp_func *func; 528 - func = list_entry(list, struct acpiphp_func, sibling); 531 + next = slot->next; 532 + list_for_each_entry_safe(func, tmp, &slot->funcs, sibling) { 529 533 if (is_dock_device(func->handle)) { 530 534 unregister_hotplug_dock_device(func->handle); 531 535 unregister_dock_notifier(&func->nb); ··· 535 543 if (ACPI_FAILURE(status)) 536 544 err("failed to remove notify handler\n"); 537 545 } 538 - list_del(list); 546 + list_del(&func->sibling); 539 547 kfree(func); 540 548 } 541 549 acpiphp_unregister_hotplug_slot(slot); ··· 600 608 { 601 609 acpi_status status; 602 610 struct acpiphp_func *func; 603 - struct list_head *l; 604 611 int retval = 0; 605 612 606 613 /* if already enabled, just skip */ 607 614 if (slot->flags & SLOT_POWEREDON) 608 615 goto err_exit; 609 616 610 - list_for_each (l, &slot->funcs) { 611 - func = list_entry(l, struct acpiphp_func, sibling); 612 - 617 + list_for_each_entry(func, &slot->funcs, sibling) { 613 618 if (func->flags & FUNC_HAS_PS0) { 614 619 dbg("%s: executing _PS0\n", __func__); 615 620 status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL); ··· 632 643 { 633 644 acpi_status status; 634 645 struct acpiphp_func *func; 635 - struct list_head *l; 636 646 637 647 int retval = 0; 638 648 ··· 639 651 if ((slot->flags & SLOT_POWEREDON) == 0) 640 652 goto err_exit; 641 653 642 - list_for_each (l, &slot->funcs) { 643 - func = list_entry(l, struct acpiphp_func, sibling); 644 - 654 + list_for_each_entry(func, &slot->funcs, sibling) { 645 655 if (func->flags & FUNC_HAS_PS3) { 646 656 status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL); 647 657 if (ACPI_FAILURE(status)) { ··· 766 780 { 767 781 struct pci_dev *dev; 768 782 struct pci_bus *bus = slot->bridge->pci_bus; 769 - struct list_head *l; 770 783 struct acpiphp_func *func; 771 784 int retval = 0; 772 785 int num, max, pass; ··· 805 820 } 806 821 } 807 822 808 - list_for_each (l, &slot->funcs) { 809 - func = list_entry(l, struct acpiphp_func, sibling); 823 + list_for_each_entry(func, &slot->funcs, sibling) 810 824 acpiphp_bus_add(func); 811 - } 812 825 813 826 pci_bus_assign_resources(bus); 814 827 acpiphp_sanitize_bus(bus); ··· 814 831 pci_enable_bridges(bus); 815 832 pci_bus_add_devices(bus); 816 833 817 - list_for_each (l, &slot->funcs) { 818 - func = list_entry(l, struct acpiphp_func, sibling); 834 + list_for_each_entry(func, &slot->funcs, sibling) { 819 835 dev = pci_get_slot(bus, PCI_DEVFN(slot->device, 820 836 func->function)); 821 837 if (!dev) ··· 912 930 acpi_status status; 913 931 unsigned long long sta = 0; 914 932 u32 dvid; 915 - struct list_head *l; 916 933 struct acpiphp_func *func; 917 934 918 - list_for_each (l, &slot->funcs) { 919 - func = list_entry(l, struct acpiphp_func, sibling); 920 - 935 + list_for_each_entry(func, &slot->funcs, sibling) { 921 936 if (func->flags & FUNC_HAS_STA) { 922 937 status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta); 923 938 if (ACPI_SUCCESS(status) && sta) ··· 942 963 { 943 964 acpi_status status; 944 965 struct acpiphp_func *func; 945 - struct list_head *l; 946 966 struct acpi_object_list arg_list; 947 967 union acpi_object arg; 948 968 949 - list_for_each (l, &slot->funcs) { 950 - func = list_entry(l, struct acpiphp_func, sibling); 951 - 969 + list_for_each_entry(func, &slot->funcs, sibling) { 952 970 /* We don't want to call _EJ0 on non-existing functions. */ 953 971 if ((func->flags & FUNC_HAS_EJ0)) { 954 972 /* _EJ0 method take one argument */ ··· 1328 1352 struct acpiphp_bridge *bridge; 1329 1353 int num_slots = 0; 1330 1354 1331 - list_for_each_entry (bridge, &bridge_list, list) { 1355 + list_for_each_entry(bridge, &bridge_list, list) { 1332 1356 dbg("Bus %04x:%02x has %d slot%s\n", 1333 1357 pci_domain_nr(bridge->pci_bus), 1334 1358 bridge->pci_bus->number, bridge->nr_slots,