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

PCI: hotplug: Use list_for_each_entry() to simplify code

Use list_for_each_entry() instead of list_for_each() to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@163.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

authored by

Geliang Tang and committed by
Bjorn Helgaas
2ac83ccc 1b47fd45

+46 -88
+6 -15
drivers/pci/hotplug/ibmphp_core.c
··· 116 116 static int __init get_max_slots (void) 117 117 { 118 118 struct slot *slot_cur; 119 - struct list_head *tmp; 120 119 u8 slot_count = 0; 121 120 122 - list_for_each(tmp, &ibmphp_slot_head) { 123 - slot_cur = list_entry(tmp, struct slot, ibm_slot_list); 121 + list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) { 124 122 /* sometimes the hot-pluggable slots start with 4 (not always from 1) */ 125 123 slot_count = max(slot_count, slot_cur->number); 126 124 } ··· 499 501 static int __init init_ops(void) 500 502 { 501 503 struct slot *slot_cur; 502 - struct list_head *tmp; 503 504 int retval; 504 505 int rc; 505 506 506 - list_for_each(tmp, &ibmphp_slot_head) { 507 - slot_cur = list_entry(tmp, struct slot, ibm_slot_list); 508 - 507 + list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) { 509 508 if (!slot_cur) 510 509 return -ENODEV; 511 510 ··· 664 669 { 665 670 struct pci_func *func_cur; 666 671 struct slot *slot_cur; 667 - struct list_head *tmp; 668 - list_for_each(tmp, &ibmphp_slot_head) { 669 - slot_cur = list_entry(tmp, struct slot, ibm_slot_list); 672 + list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) { 670 673 if (slot_cur->func) { 671 674 func_cur = slot_cur->func; 672 675 while (func_cur) { ··· 686 693 *************************************************************/ 687 694 static void free_slots(void) 688 695 { 689 - struct slot *slot_cur; 690 - struct list_head *tmp; 691 - struct list_head *next; 696 + struct slot *slot_cur, *next; 692 697 693 698 debug("%s -- enter\n", __func__); 694 699 695 - list_for_each_safe(tmp, next, &ibmphp_slot_head) { 696 - slot_cur = list_entry(tmp, struct slot, ibm_slot_list); 700 + list_for_each_entry_safe(slot_cur, next, &ibmphp_slot_head, 701 + ibm_slot_list) { 697 702 pci_hp_deregister(slot_cur->hotplug_slot); 698 703 } 699 704 debug("%s -- exit\n", __func__);
+9 -15
drivers/pci/hotplug/ibmphp_ebda.c
··· 1117 1117 1118 1118 void ibmphp_free_bus_info_queue (void) 1119 1119 { 1120 - struct bus_info *bus_info; 1121 - struct list_head *list; 1122 - struct list_head *next; 1120 + struct bus_info *bus_info, *next; 1123 1121 1124 - list_for_each_safe (list, next, &bus_info_head ) { 1125 - bus_info = list_entry (list, struct bus_info, bus_info_list); 1122 + list_for_each_entry_safe(bus_info, next, &bus_info_head, 1123 + bus_info_list) { 1126 1124 kfree (bus_info); 1127 1125 } 1128 1126 } 1129 1127 1130 1128 void ibmphp_free_ebda_hpc_queue (void) 1131 1129 { 1132 - struct controller *controller = NULL; 1133 - struct list_head *list; 1134 - struct list_head *next; 1130 + struct controller *controller = NULL, *next; 1135 1131 int pci_flag = 0; 1136 1132 1137 - list_for_each_safe (list, next, &ebda_hpc_head) { 1138 - controller = list_entry (list, struct controller, ebda_hpc_list); 1133 + list_for_each_entry_safe(controller, next, &ebda_hpc_head, 1134 + ebda_hpc_list) { 1139 1135 if (controller->ctlr_type == 0) 1140 1136 release_region (controller->u.isa_ctlr.io_start, (controller->u.isa_ctlr.io_end - controller->u.isa_ctlr.io_start + 1)); 1141 1137 else if ((controller->ctlr_type == 1) && (!pci_flag)) { ··· 1144 1148 1145 1149 void ibmphp_free_ebda_pci_rsrc_queue (void) 1146 1150 { 1147 - struct ebda_pci_rsrc *resource; 1148 - struct list_head *list; 1149 - struct list_head *next; 1151 + struct ebda_pci_rsrc *resource, *next; 1150 1152 1151 - list_for_each_safe (list, next, &ibmphp_ebda_pci_rsrc_head) { 1152 - resource = list_entry (list, struct ebda_pci_rsrc, ebda_pci_rsrc_list); 1153 + list_for_each_entry_safe(resource, next, &ibmphp_ebda_pci_rsrc_head, 1154 + ebda_pci_rsrc_list) { 1153 1155 kfree (resource); 1154 1156 resource = NULL; 1155 1157 }
+8 -10
drivers/pci/hotplug/ibmphp_hpc.c
··· 537 537 { 538 538 void __iomem *wpg_bbar = NULL; 539 539 struct controller *ctlr_ptr; 540 - struct list_head *pslotlist; 541 540 u8 index, status; 542 541 int rc = 0; 543 542 int busindex; ··· 627 628 628 629 // Not used 629 630 case READ_ALLSLOT: 630 - list_for_each (pslotlist, &ibmphp_slot_head) { 631 - pslot = list_entry (pslotlist, struct slot, ibm_slot_list); 631 + list_for_each_entry(pslot, &ibmphp_slot_head, 632 + ibm_slot_list) { 632 633 index = pslot->ctlr_index; 633 634 rc = hpc_wait_ctlr_notworking (HPC_CTLR_WORKING_TOUT, ctlr_ptr, 634 635 wpg_bbar, &status); ··· 819 820 { 820 821 struct slot myslot; 821 822 struct slot *pslot = NULL; 822 - struct list_head *pslotlist; 823 823 int rc; 824 824 int poll_state = POLL_LATCH_REGISTER; 825 825 u8 oldlatchlow = 0x00; ··· 836 838 case POLL_LATCH_REGISTER: 837 839 oldlatchlow = curlatchlow; 838 840 ctrl_count = 0x00; 839 - list_for_each (pslotlist, &ibmphp_slot_head) { 841 + list_for_each_entry(pslot, &ibmphp_slot_head, 842 + ibm_slot_list) { 840 843 if (ctrl_count >= ibmphp_get_total_controllers()) 841 844 break; 842 - pslot = list_entry (pslotlist, struct slot, ibm_slot_list); 843 845 if (pslot->ctrl->ctlr_relative_id == ctrl_count) { 844 846 ctrl_count++; 845 847 if (READ_SLOT_LATCH (pslot->ctrl)) { ··· 857 859 poll_state = POLL_SLEEP; 858 860 break; 859 861 case POLL_SLOTS: 860 - list_for_each (pslotlist, &ibmphp_slot_head) { 861 - pslot = list_entry (pslotlist, struct slot, ibm_slot_list); 862 + list_for_each_entry(pslot, &ibmphp_slot_head, 863 + ibm_slot_list) { 862 864 // make a copy of the old status 863 865 memcpy ((void *) &myslot, (void *) pslot, 864 866 sizeof (struct slot)); ··· 868 870 process_changeinstatus (pslot, &myslot); 869 871 } 870 872 ctrl_count = 0x00; 871 - list_for_each (pslotlist, &ibmphp_slot_head) { 873 + list_for_each_entry(pslot, &ibmphp_slot_head, 874 + ibm_slot_list) { 872 875 if (ctrl_count >= ibmphp_get_total_controllers()) 873 876 break; 874 - pslot = list_entry (pslotlist, struct slot, ibm_slot_list); 875 877 if (pslot->ctrl->ctlr_relative_id == ctrl_count) { 876 878 ctrl_count++; 877 879 if (READ_SLOT_LATCH (pslot->ctrl))
+9 -23
drivers/pci/hotplug/ibmphp_res.c
··· 203 203 struct bus_node *newbus = NULL; 204 204 struct bus_node *bus_cur; 205 205 struct bus_node *bus_prev; 206 - struct list_head *tmp; 207 206 struct resource_node *new_io = NULL; 208 207 struct resource_node *new_mem = NULL; 209 208 struct resource_node *new_pfmem = NULL; 210 209 int rc; 211 - struct list_head *tmp_ebda; 212 210 213 - list_for_each (tmp_ebda, &ibmphp_ebda_pci_rsrc_head) { 214 - curr = list_entry (tmp_ebda, struct ebda_pci_rsrc, ebda_pci_rsrc_list); 211 + list_for_each_entry(curr, &ibmphp_ebda_pci_rsrc_head, 212 + ebda_pci_rsrc_list) { 215 213 if (!(curr->rsrc_type & PCIDEVMASK)) { 216 214 /* EBDA still lists non PCI devices, so ignore... */ 217 215 debug ("this is not a PCI DEVICE in rsrc_init, please take care\n"); ··· 367 369 } 368 370 } 369 371 370 - list_for_each (tmp, &gbuses) { 371 - bus_cur = list_entry (tmp, struct bus_node, bus_list); 372 + list_for_each_entry(bus_cur, &gbuses, bus_list) { 372 373 /* This is to get info about PPB resources, since EBDA doesn't put this info into the primary bus info */ 373 374 rc = update_bridge_ranges (&bus_cur); 374 375 if (rc) ··· 1568 1571 ***********************************************************************/ 1569 1572 void ibmphp_free_resources (void) 1570 1573 { 1571 - struct bus_node *bus_cur = NULL; 1574 + struct bus_node *bus_cur = NULL, *next; 1572 1575 struct bus_node *bus_tmp; 1573 1576 struct range_node *range_cur; 1574 1577 struct range_node *range_tmp; 1575 1578 struct resource_node *res_cur; 1576 1579 struct resource_node *res_tmp; 1577 - struct list_head *tmp; 1578 - struct list_head *next; 1579 1580 int i = 0; 1580 1581 flags = 1; 1581 1582 1582 - list_for_each_safe (tmp, next, &gbuses) { 1583 - bus_cur = list_entry (tmp, struct bus_node, bus_list); 1583 + list_for_each_entry_safe(bus_cur, next, &gbuses, bus_list) { 1584 1584 if (bus_cur->noIORanges) { 1585 1585 range_cur = bus_cur->rangeIO; 1586 1586 for (i = 0; i < bus_cur->noIORanges; i++) { ··· 1685 1691 struct resource_node *pfmem_prev; 1686 1692 struct resource_node *mem; 1687 1693 struct bus_node *bus_cur; 1688 - struct list_head *tmp; 1689 1694 1690 - list_for_each (tmp, &gbuses) { 1691 - bus_cur = list_entry (tmp, struct bus_node, bus_list); 1695 + list_for_each_entry(bus_cur, &gbuses, bus_list) { 1692 1696 if ((!bus_cur->rangePFMem) && (bus_cur->firstPFMem)) { 1693 1697 for (pfmem_cur = bus_cur->firstPFMem, pfmem_prev = NULL; pfmem_cur; pfmem_prev = pfmem_cur, pfmem_cur = pfmem_cur->next) { 1694 1698 pfmem_cur->fromMem = 1; ··· 1759 1767 static struct bus_node *find_bus_wprev (u8 bus_number, struct bus_node **prev, u8 flag) 1760 1768 { 1761 1769 struct bus_node *bus_cur; 1762 - struct list_head *tmp; 1763 - struct list_head *tmp_prev; 1764 1770 1765 - list_for_each (tmp, &gbuses) { 1766 - tmp_prev = tmp->prev; 1767 - bus_cur = list_entry (tmp, struct bus_node, bus_list); 1771 + list_for_each_entry(bus_cur, &gbuses, bus_list) { 1768 1772 if (flag) 1769 - *prev = list_entry (tmp_prev, struct bus_node, bus_list); 1773 + *prev = list_prev_entry(bus_cur, bus_list); 1770 1774 if (bus_cur->busno == bus_number) 1771 1775 return bus_cur; 1772 1776 } ··· 1776 1788 struct bus_node *bus_cur = NULL; 1777 1789 struct range_node *range; 1778 1790 struct resource_node *res; 1779 - struct list_head *tmp; 1780 1791 1781 1792 debug_pci ("*****************START**********************\n"); 1782 1793 ··· 1784 1797 return; 1785 1798 } 1786 1799 1787 - list_for_each (tmp, &gbuses) { 1788 - bus_cur = list_entry (tmp, struct bus_node, bus_list); 1800 + list_for_each_entry(bus_cur, &gbuses, bus_list) { 1789 1801 debug_pci ("This is bus # %d. There are\n", bus_cur->busno); 1790 1802 debug_pci ("IORanges = %d\t", bus_cur->noIORanges); 1791 1803 debug_pci ("MemRanges = %d\t", bus_cur->noMemRanges);
+1 -3
drivers/pci/hotplug/pci_hotplug_core.c
··· 396 396 static struct hotplug_slot *get_slot_from_name(const char *name) 397 397 { 398 398 struct hotplug_slot *slot; 399 - struct list_head *tmp; 400 399 401 - list_for_each(tmp, &pci_hotplug_slot_list) { 402 - slot = list_entry(tmp, struct hotplug_slot, slot_list); 400 + list_for_each_entry(slot, &pci_hotplug_slot_list, slot_list) { 403 401 if (strcmp(hotplug_slot_name(slot), name) == 0) 404 402 return slot; 405 403 }
+2 -5
drivers/pci/hotplug/pcihp_skeleton.c
··· 321 321 322 322 static void __exit cleanup_slots(void) 323 323 { 324 - struct list_head *tmp; 325 - struct list_head *next; 326 - struct slot *slot; 324 + struct slot *slot, *next; 327 325 328 326 /* 329 327 * Unregister all of our slots with the pci_hotplug subsystem. 330 328 * Memory will be freed in release_slot() callback after slot's 331 329 * lifespan is finished. 332 330 */ 333 - list_for_each_safe(tmp, next, &slot_list) { 334 - slot = list_entry(tmp, struct slot, slot_list); 331 + list_for_each_entry_safe(slot, next, &slot_list, slot_list) { 335 332 list_del(&slot->slot_list); 336 333 pci_hp_deregister(slot->hotplug_slot); 337 334 }
+3 -4
drivers/pci/hotplug/rpadlpar_core.c
··· 114 114 */ 115 115 static struct slot *find_php_slot(struct device_node *dn) 116 116 { 117 - struct list_head *tmp, *n; 118 - struct slot *slot; 117 + struct slot *slot, *next; 119 118 120 - list_for_each_safe(tmp, n, &rpaphp_slot_head) { 121 - slot = list_entry(tmp, struct slot, rpaphp_slot_list); 119 + list_for_each_entry_safe(slot, next, &rpaphp_slot_head, 120 + rpaphp_slot_list) { 122 121 if (slot->dn == dn) 123 122 return slot; 124 123 }
+3 -4
drivers/pci/hotplug/rpaphp_core.c
··· 356 356 357 357 static void __exit cleanup_slots(void) 358 358 { 359 - struct list_head *tmp, *n; 360 - struct slot *slot; 359 + struct slot *slot, *next; 361 360 362 361 /* 363 362 * Unregister all of our slots with the pci_hotplug subsystem, ··· 364 365 * memory will be freed in release_slot callback. 365 366 */ 366 367 367 - list_for_each_safe(tmp, n, &rpaphp_slot_head) { 368 - slot = list_entry(tmp, struct slot, rpaphp_slot_list); 368 + list_for_each_entry_safe(slot, next, &rpaphp_slot_head, 369 + rpaphp_slot_list) { 369 370 list_del(&slot->rpaphp_slot_list); 370 371 pci_hp_deregister(slot->hotplug_slot); 371 372 }
+3 -4
drivers/pci/hotplug/s390_pci_hpc.c
··· 201 201 202 202 void zpci_exit_slot(struct zpci_dev *zdev) 203 203 { 204 - struct list_head *tmp, *n; 205 - struct slot *slot; 204 + struct slot *slot, *next; 206 205 207 - list_for_each_safe(tmp, n, &s390_hotplug_slot_list) { 208 - slot = list_entry(tmp, struct slot, slot_list); 206 + list_for_each_entry_safe(slot, next, &s390_hotplug_slot_list, 207 + slot_list) { 209 208 if (slot->zdev != zdev) 210 209 continue; 211 210 list_del(&slot->slot_list);
+2 -5
drivers/pci/hotplug/shpchp_core.c
··· 178 178 179 179 void cleanup_slots(struct controller *ctrl) 180 180 { 181 - struct list_head *tmp; 182 - struct list_head *next; 183 - struct slot *slot; 181 + struct slot *slot, *next; 184 182 185 - list_for_each_safe(tmp, next, &ctrl->slot_list) { 186 - slot = list_entry(tmp, struct slot, slot_list); 183 + list_for_each_entry_safe(slot, next, &ctrl->slot_list, slot_list) { 187 184 list_del(&slot->slot_list); 188 185 cancel_delayed_work(&slot->work); 189 186 destroy_workqueue(slot->wq);