aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
authorAlex Chiang <achiang@hp.com>2009-10-26 23:25:27 -0400
committerJesse Barnes <jbarnes@virtuousgeek.org>2009-11-04 16:06:40 -0500
commit58c08628c4fe664bfd5f8b7e773b4b157bb9686f (patch)
treea0eb74068dd019238af73e0569e9351d473a48eb /drivers/pci
parent204d49a5613a06eb2fa5c3b842a29b1336cc7995 (diff)
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>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c58
1 files changed, 17 insertions, 41 deletions
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 392e4b3fa2e4..8f4a2073d83a 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -309,17 +309,13 @@ static void init_bridge_misc(struct acpiphp_bridge *bridge)
309/* find acpiphp_func from acpiphp_bridge */ 309/* find acpiphp_func from acpiphp_bridge */
310static struct acpiphp_func *acpiphp_bridge_handle_to_function(acpi_handle handle) 310static struct acpiphp_func *acpiphp_bridge_handle_to_function(acpi_handle handle)
311{ 311{
312 struct list_head *node, *l;
313 struct acpiphp_bridge *bridge; 312 struct acpiphp_bridge *bridge;
314 struct acpiphp_slot *slot; 313 struct acpiphp_slot *slot;
315 struct acpiphp_func *func; 314 struct acpiphp_func *func;
316 315
317 list_for_each(node, &bridge_list) { 316 list_for_each_entry(bridge, &bridge_list, list) {
318 bridge = list_entry(node, struct acpiphp_bridge, list);
319 for (slot = bridge->slots; slot; slot = slot->next) { 317 for (slot = bridge->slots; slot; slot = slot->next) {
320 list_for_each(l, &slot->funcs) { 318 list_for_each_entry(func, &slot->funcs, sibling) {
321 func = list_entry(l, struct acpiphp_func,
322 sibling);
323 if (func->handle == handle) 319 if (func->handle == handle)
324 return func; 320 return func;
325 } 321 }
@@ -493,21 +489,19 @@ static int add_bridge(acpi_handle handle)
493 489
494static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) 490static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
495{ 491{
496 struct list_head *head; 492 struct acpiphp_bridge *bridge;
497 list_for_each(head, &bridge_list) { 493
498 struct acpiphp_bridge *bridge = list_entry(head, 494 list_for_each_entry(bridge, &bridge_list, list)
499 struct acpiphp_bridge, list);
500 if (bridge->handle == handle) 495 if (bridge->handle == handle)
501 return bridge; 496 return bridge;
502 }
503 497
504 return NULL; 498 return NULL;
505} 499}
506 500
507static void cleanup_bridge(struct acpiphp_bridge *bridge) 501static void cleanup_bridge(struct acpiphp_bridge *bridge)
508{ 502{
509 struct list_head *list, *tmp; 503 struct acpiphp_slot *slot, *next;
510 struct acpiphp_slot *slot; 504 struct acpiphp_func *func, *tmp;
511 acpi_status status; 505 acpi_status status;
512 acpi_handle handle = bridge->handle; 506 acpi_handle handle = bridge->handle;
513 507
@@ -528,10 +522,8 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge)
528 522
529 slot = bridge->slots; 523 slot = bridge->slots;
530 while (slot) { 524 while (slot) {
531 struct acpiphp_slot *next = slot->next; 525 next = slot->next;
532 list_for_each_safe (list, tmp, &slot->funcs) { 526 list_for_each_entry_safe(func, tmp, &slot->funcs, sibling) {
533 struct acpiphp_func *func;
534 func = list_entry(list, struct acpiphp_func, sibling);
535 if (is_dock_device(func->handle)) { 527 if (is_dock_device(func->handle)) {
536 unregister_hotplug_dock_device(func->handle); 528 unregister_hotplug_dock_device(func->handle);
537 unregister_dock_notifier(&func->nb); 529 unregister_dock_notifier(&func->nb);
@@ -543,7 +535,7 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge)
543 if (ACPI_FAILURE(status)) 535 if (ACPI_FAILURE(status))
544 err("failed to remove notify handler\n"); 536 err("failed to remove notify handler\n");
545 } 537 }
546 list_del(list); 538 list_del(&func->sibling);
547 kfree(func); 539 kfree(func);
548 } 540 }
549 acpiphp_unregister_hotplug_slot(slot); 541 acpiphp_unregister_hotplug_slot(slot);
@@ -608,16 +600,13 @@ static int power_on_slot(struct acpiphp_slot *slot)
608{ 600{
609 acpi_status status; 601 acpi_status status;
610 struct acpiphp_func *func; 602 struct acpiphp_func *func;
611 struct list_head *l;
612 int retval = 0; 603 int retval = 0;
613 604
614 /* if already enabled, just skip */ 605 /* if already enabled, just skip */
615 if (slot->flags & SLOT_POWEREDON) 606 if (slot->flags & SLOT_POWEREDON)
616 goto err_exit; 607 goto err_exit;
617 608
618 list_for_each (l, &slot->funcs) { 609 list_for_each_entry(func, &slot->funcs, sibling) {
619 func = list_entry(l, struct acpiphp_func, sibling);
620
621 if (func->flags & FUNC_HAS_PS0) { 610 if (func->flags & FUNC_HAS_PS0) {
622 dbg("%s: executing _PS0\n", __func__); 611 dbg("%s: executing _PS0\n", __func__);
623 status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL); 612 status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL);
@@ -643,7 +632,6 @@ static int power_off_slot(struct acpiphp_slot *slot)
643{ 632{
644 acpi_status status; 633 acpi_status status;
645 struct acpiphp_func *func; 634 struct acpiphp_func *func;
646 struct list_head *l;
647 635
648 int retval = 0; 636 int retval = 0;
649 637
@@ -651,9 +639,7 @@ static int power_off_slot(struct acpiphp_slot *slot)
651 if ((slot->flags & SLOT_POWEREDON) == 0) 639 if ((slot->flags & SLOT_POWEREDON) == 0)
652 goto err_exit; 640 goto err_exit;
653 641
654 list_for_each (l, &slot->funcs) { 642 list_for_each_entry(func, &slot->funcs, sibling) {
655 func = list_entry(l, struct acpiphp_func, sibling);
656
657 if (func->flags & FUNC_HAS_PS3) { 643 if (func->flags & FUNC_HAS_PS3) {
658 status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL); 644 status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL);
659 if (ACPI_FAILURE(status)) { 645 if (ACPI_FAILURE(status)) {
@@ -780,7 +766,6 @@ static int __ref enable_device(struct acpiphp_slot *slot)
780{ 766{
781 struct pci_dev *dev; 767 struct pci_dev *dev;
782 struct pci_bus *bus = slot->bridge->pci_bus; 768 struct pci_bus *bus = slot->bridge->pci_bus;
783 struct list_head *l;
784 struct acpiphp_func *func; 769 struct acpiphp_func *func;
785 int retval = 0; 770 int retval = 0;
786 int num, max, pass; 771 int num, max, pass;
@@ -820,10 +805,8 @@ static int __ref enable_device(struct acpiphp_slot *slot)
820 } 805 }
821 } 806 }
822 807
823 list_for_each (l, &slot->funcs) { 808 list_for_each_entry(func, &slot->funcs, sibling)
824 func = list_entry(l, struct acpiphp_func, sibling);
825 acpiphp_bus_add(func); 809 acpiphp_bus_add(func);
826 }
827 810
828 pci_bus_assign_resources(bus); 811 pci_bus_assign_resources(bus);
829 acpiphp_sanitize_bus(bus); 812 acpiphp_sanitize_bus(bus);
@@ -831,8 +814,7 @@ static int __ref enable_device(struct acpiphp_slot *slot)
831 pci_enable_bridges(bus); 814 pci_enable_bridges(bus);
832 pci_bus_add_devices(bus); 815 pci_bus_add_devices(bus);
833 816
834 list_for_each (l, &slot->funcs) { 817 list_for_each_entry(func, &slot->funcs, sibling) {
835 func = list_entry(l, struct acpiphp_func, sibling);
836 dev = pci_get_slot(bus, PCI_DEVFN(slot->device, 818 dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
837 func->function)); 819 func->function));
838 if (!dev) 820 if (!dev)
@@ -930,12 +912,9 @@ static unsigned int get_slot_status(struct acpiphp_slot *slot)
930 acpi_status status; 912 acpi_status status;
931 unsigned long long sta = 0; 913 unsigned long long sta = 0;
932 u32 dvid; 914 u32 dvid;
933 struct list_head *l;
934 struct acpiphp_func *func; 915 struct acpiphp_func *func;
935 916
936 list_for_each (l, &slot->funcs) { 917 list_for_each_entry(func, &slot->funcs, sibling) {
937 func = list_entry(l, struct acpiphp_func, sibling);
938
939 if (func->flags & FUNC_HAS_STA) { 918 if (func->flags & FUNC_HAS_STA) {
940 status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta); 919 status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta);
941 if (ACPI_SUCCESS(status) && sta) 920 if (ACPI_SUCCESS(status) && sta)
@@ -963,13 +942,10 @@ int acpiphp_eject_slot(struct acpiphp_slot *slot)
963{ 942{
964 acpi_status status; 943 acpi_status status;
965 struct acpiphp_func *func; 944 struct acpiphp_func *func;
966 struct list_head *l;
967 struct acpi_object_list arg_list; 945 struct acpi_object_list arg_list;
968 union acpi_object arg; 946 union acpi_object arg;
969 947
970 list_for_each (l, &slot->funcs) { 948 list_for_each_entry(func, &slot->funcs, sibling) {
971 func = list_entry(l, struct acpiphp_func, sibling);
972
973 /* We don't want to call _EJ0 on non-existing functions. */ 949 /* We don't want to call _EJ0 on non-existing functions. */
974 if ((func->flags & FUNC_HAS_EJ0)) { 950 if ((func->flags & FUNC_HAS_EJ0)) {
975 /* _EJ0 method take one argument */ 951 /* _EJ0 method take one argument */
@@ -1352,7 +1328,7 @@ int __init acpiphp_get_num_slots(void)
1352 struct acpiphp_bridge *bridge; 1328 struct acpiphp_bridge *bridge;
1353 int num_slots = 0; 1329 int num_slots = 0;
1354 1330
1355 list_for_each_entry (bridge, &bridge_list, list) { 1331 list_for_each_entry(bridge, &bridge_list, list) {
1356 dbg("Bus %04x:%02x has %d slot%s\n", 1332 dbg("Bus %04x:%02x has %d slot%s\n",
1357 pci_domain_nr(bridge->pci_bus), 1333 pci_domain_nr(bridge->pci_bus),
1358 bridge->pci_bus->number, bridge->nr_slots, 1334 bridge->pci_bus->number, bridge->nr_slots,