Skip to content

Commit 2ac83cc

Browse files
geliangtangbjorn-helgaas
authored andcommitted
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>
1 parent 1b47fd4 commit 2ac83cc

10 files changed

Lines changed: 46 additions & 88 deletions

File tree

‎drivers/pci/hotplug/ibmphp_core.c‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,9 @@ static inline int slot_update(struct slot **sl)
116116
static int __init get_max_slots (void)
117117
{
118118
struct slot *slot_cur;
119-
struct list_head *tmp;
120119
u8 slot_count = 0;
121120

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) {
124122
/* sometimes the hot-pluggable slots start with 4 (not always from 1) */
125123
slot_count = max(slot_count, slot_cur->number);
126124
}
@@ -501,13 +499,10 @@ static int get_bus_name(struct hotplug_slot *hotplug_slot, char *value)
501499
static int __init init_ops(void)
502500
{
503501
struct slot *slot_cur;
504-
struct list_head *tmp;
505502
int retval;
506503
int rc;
507504

508-
list_for_each(tmp, &ibmphp_slot_head) {
509-
slot_cur = list_entry(tmp, struct slot, ibm_slot_list);
510-
505+
list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) {
511506
if (!slot_cur)
512507
return -ENODEV;
513508

@@ -669,9 +664,7 @@ static struct pci_func *ibm_slot_find(u8 busno, u8 device, u8 function)
669664
{
670665
struct pci_func *func_cur;
671666
struct slot *slot_cur;
672-
struct list_head *tmp;
673-
list_for_each(tmp, &ibmphp_slot_head) {
674-
slot_cur = list_entry(tmp, struct slot, ibm_slot_list);
667+
list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) {
675668
if (slot_cur->func) {
676669
func_cur = slot_cur->func;
677670
while (func_cur) {
@@ -693,14 +686,12 @@ static struct pci_func *ibm_slot_find(u8 busno, u8 device, u8 function)
693686
*************************************************************/
694687
static void free_slots(void)
695688
{
696-
struct slot *slot_cur;
697-
struct list_head *tmp;
698-
struct list_head *next;
689+
struct slot *slot_cur, *next;
699690

700691
debug("%s -- enter\n", __func__);
701692

702-
list_for_each_safe(tmp, next, &ibmphp_slot_head) {
703-
slot_cur = list_entry(tmp, struct slot, ibm_slot_list);
693+
list_for_each_entry_safe(slot_cur, next, &ibmphp_slot_head,
694+
ibm_slot_list) {
704695
pci_hp_deregister(slot_cur->hotplug_slot);
705696
}
706697
debug("%s -- exit\n", __func__);

‎drivers/pci/hotplug/ibmphp_ebda.c‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,25 +1117,21 @@ int ibmphp_get_bus_index (u8 num)
11171117

11181118
void ibmphp_free_bus_info_queue (void)
11191119
{
1120-
struct bus_info *bus_info;
1121-
struct list_head *list;
1122-
struct list_head *next;
1120+
struct bus_info *bus_info, *next;
11231121

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) {
11261124
kfree (bus_info);
11271125
}
11281126
}
11291127

11301128
void ibmphp_free_ebda_hpc_queue (void)
11311129
{
1132-
struct controller *controller = NULL;
1133-
struct list_head *list;
1134-
struct list_head *next;
1130+
struct controller *controller = NULL, *next;
11351131
int pci_flag = 0;
11361132

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) {
11391135
if (controller->ctlr_type == 0)
11401136
release_region (controller->u.isa_ctlr.io_start, (controller->u.isa_ctlr.io_end - controller->u.isa_ctlr.io_start + 1));
11411137
else if ((controller->ctlr_type == 1) && (!pci_flag)) {
@@ -1148,12 +1144,10 @@ void ibmphp_free_ebda_hpc_queue (void)
11481144

11491145
void ibmphp_free_ebda_pci_rsrc_queue (void)
11501146
{
1151-
struct ebda_pci_rsrc *resource;
1152-
struct list_head *list;
1153-
struct list_head *next;
1147+
struct ebda_pci_rsrc *resource, *next;
11541148

1155-
list_for_each_safe (list, next, &ibmphp_ebda_pci_rsrc_head) {
1156-
resource = list_entry (list, struct ebda_pci_rsrc, ebda_pci_rsrc_list);
1149+
list_for_each_entry_safe(resource, next, &ibmphp_ebda_pci_rsrc_head,
1150+
ebda_pci_rsrc_list) {
11571151
kfree (resource);
11581152
resource = NULL;
11591153
}

‎drivers/pci/hotplug/ibmphp_hpc.c‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,6 @@ int ibmphp_hpc_readslot (struct slot *pslot, u8 cmd, u8 *pstatus)
537537
{
538538
void __iomem *wpg_bbar = NULL;
539539
struct controller *ctlr_ptr;
540-
struct list_head *pslotlist;
541540
u8 index, status;
542541
int rc = 0;
543542
int busindex;
@@ -628,8 +627,8 @@ int ibmphp_hpc_readslot (struct slot *pslot, u8 cmd, u8 *pstatus)
628627

629628
// Not used
630629
case READ_ALLSLOT:
631-
list_for_each (pslotlist, &ibmphp_slot_head) {
632-
pslot = list_entry (pslotlist, struct slot, ibm_slot_list);
630+
list_for_each_entry(pslot, &ibmphp_slot_head,
631+
ibm_slot_list) {
633632
index = pslot->ctlr_index;
634633
rc = hpc_wait_ctlr_notworking (HPC_CTLR_WORKING_TOUT, ctlr_ptr,
635634
wpg_bbar, &status);
@@ -820,7 +819,6 @@ static int poll_hpc(void *data)
820819
{
821820
struct slot myslot;
822821
struct slot *pslot = NULL;
823-
struct list_head *pslotlist;
824822
int rc;
825823
int poll_state = POLL_LATCH_REGISTER;
826824
u8 oldlatchlow = 0x00;
@@ -838,10 +836,10 @@ static int poll_hpc(void *data)
838836
case POLL_LATCH_REGISTER:
839837
oldlatchlow = curlatchlow;
840838
ctrl_count = 0x00;
841-
list_for_each (pslotlist, &ibmphp_slot_head) {
839+
list_for_each_entry(pslot, &ibmphp_slot_head,
840+
ibm_slot_list) {
842841
if (ctrl_count >= ibmphp_get_total_controllers())
843842
break;
844-
pslot = list_entry (pslotlist, struct slot, ibm_slot_list);
845843
if (pslot->ctrl->ctlr_relative_id == ctrl_count) {
846844
ctrl_count++;
847845
if (READ_SLOT_LATCH (pslot->ctrl)) {
@@ -859,8 +857,8 @@ static int poll_hpc(void *data)
859857
poll_state = POLL_SLEEP;
860858
break;
861859
case POLL_SLOTS:
862-
list_for_each (pslotlist, &ibmphp_slot_head) {
863-
pslot = list_entry (pslotlist, struct slot, ibm_slot_list);
860+
list_for_each_entry(pslot, &ibmphp_slot_head,
861+
ibm_slot_list) {
864862
// make a copy of the old status
865863
memcpy ((void *) &myslot, (void *) pslot,
866864
sizeof (struct slot));
@@ -870,10 +868,10 @@ static int poll_hpc(void *data)
870868
process_changeinstatus (pslot, &myslot);
871869
}
872870
ctrl_count = 0x00;
873-
list_for_each (pslotlist, &ibmphp_slot_head) {
871+
list_for_each_entry(pslot, &ibmphp_slot_head,
872+
ibm_slot_list) {
874873
if (ctrl_count >= ibmphp_get_total_controllers())
875874
break;
876-
pslot = list_entry (pslotlist, struct slot, ibm_slot_list);
877875
if (pslot->ctrl->ctlr_relative_id == ctrl_count) {
878876
ctrl_count++;
879877
if (READ_SLOT_LATCH (pslot->ctrl))

‎drivers/pci/hotplug/ibmphp_res.c‎

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,13 @@ int __init ibmphp_rsrc_init (void)
203203
struct bus_node *newbus = NULL;
204204
struct bus_node *bus_cur;
205205
struct bus_node *bus_prev;
206-
struct list_head *tmp;
207206
struct resource_node *new_io = NULL;
208207
struct resource_node *new_mem = NULL;
209208
struct resource_node *new_pfmem = NULL;
210209
int rc;
211-
struct list_head *tmp_ebda;
212210

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) {
215213
if (!(curr->rsrc_type & PCIDEVMASK)) {
216214
/* EBDA still lists non PCI devices, so ignore... */
217215
debug ("this is not a PCI DEVICE in rsrc_init, please take care\n");
@@ -369,8 +367,7 @@ int __init ibmphp_rsrc_init (void)
369367
}
370368
}
371369

372-
list_for_each (tmp, &gbuses) {
373-
bus_cur = list_entry (tmp, struct bus_node, bus_list);
370+
list_for_each_entry(bus_cur, &gbuses, bus_list) {
374371
/* This is to get info about PPB resources, since EBDA doesn't put this info into the primary bus info */
375372
rc = update_bridge_ranges (&bus_cur);
376373
if (rc)
@@ -1571,19 +1568,16 @@ int ibmphp_find_resource (struct bus_node *bus, u32 start_address, struct resour
15711568
***********************************************************************/
15721569
void ibmphp_free_resources (void)
15731570
{
1574-
struct bus_node *bus_cur = NULL;
1571+
struct bus_node *bus_cur = NULL, *next;
15751572
struct bus_node *bus_tmp;
15761573
struct range_node *range_cur;
15771574
struct range_node *range_tmp;
15781575
struct resource_node *res_cur;
15791576
struct resource_node *res_tmp;
1580-
struct list_head *tmp;
1581-
struct list_head *next;
15821577
int i = 0;
15831578
flags = 1;
15841579

1585-
list_for_each_safe (tmp, next, &gbuses) {
1586-
bus_cur = list_entry (tmp, struct bus_node, bus_list);
1580+
list_for_each_entry_safe(bus_cur, next, &gbuses, bus_list) {
15871581
if (bus_cur->noIORanges) {
15881582
range_cur = bus_cur->rangeIO;
15891583
for (i = 0; i < bus_cur->noIORanges; i++) {
@@ -1691,10 +1685,8 @@ static int __init once_over (void)
16911685
struct resource_node *pfmem_prev;
16921686
struct resource_node *mem;
16931687
struct bus_node *bus_cur;
1694-
struct list_head *tmp;
16951688

1696-
list_for_each (tmp, &gbuses) {
1697-
bus_cur = list_entry (tmp, struct bus_node, bus_list);
1689+
list_for_each_entry(bus_cur, &gbuses, bus_list) {
16981690
if ((!bus_cur->rangePFMem) && (bus_cur->firstPFMem)) {
16991691
for (pfmem_cur = bus_cur->firstPFMem, pfmem_prev = NULL; pfmem_cur; pfmem_prev = pfmem_cur, pfmem_cur = pfmem_cur->next) {
17001692
pfmem_cur->fromMem = 1;
@@ -1767,14 +1759,10 @@ struct bus_node *ibmphp_find_res_bus (u8 bus_number)
17671759
static struct bus_node *find_bus_wprev (u8 bus_number, struct bus_node **prev, u8 flag)
17681760
{
17691761
struct bus_node *bus_cur;
1770-
struct list_head *tmp;
1771-
struct list_head *tmp_prev;
17721762

1773-
list_for_each (tmp, &gbuses) {
1774-
tmp_prev = tmp->prev;
1775-
bus_cur = list_entry (tmp, struct bus_node, bus_list);
1763+
list_for_each_entry(bus_cur, &gbuses, bus_list) {
17761764
if (flag)
1777-
*prev = list_entry (tmp_prev, struct bus_node, bus_list);
1765+
*prev = list_prev_entry(bus_cur, bus_list);
17781766
if (bus_cur->busno == bus_number)
17791767
return bus_cur;
17801768
}
@@ -1788,7 +1776,6 @@ void ibmphp_print_test (void)
17881776
struct bus_node *bus_cur = NULL;
17891777
struct range_node *range;
17901778
struct resource_node *res;
1791-
struct list_head *tmp;
17921779

17931780
debug_pci ("*****************START**********************\n");
17941781

@@ -1797,8 +1784,7 @@ void ibmphp_print_test (void)
17971784
return;
17981785
}
17991786

1800-
list_for_each (tmp, &gbuses) {
1801-
bus_cur = list_entry (tmp, struct bus_node, bus_list);
1787+
list_for_each_entry(bus_cur, &gbuses, bus_list) {
18021788
debug_pci ("This is bus # %d. There are\n", bus_cur->busno);
18031789
debug_pci ("IORanges = %d\t", bus_cur->noIORanges);
18041790
debug_pci ("MemRanges = %d\t", bus_cur->noMemRanges);

‎drivers/pci/hotplug/pci_hotplug_core.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,8 @@ static void fs_remove_slot(struct pci_slot *pci_slot)
396396
static struct hotplug_slot *get_slot_from_name(const char *name)
397397
{
398398
struct hotplug_slot *slot;
399-
struct list_head *tmp;
400399

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) {
403401
if (strcmp(hotplug_slot_name(slot), name) == 0)
404402
return slot;
405403
}

‎drivers/pci/hotplug/pcihp_skeleton.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,14 @@ static int __init init_slots(void)
321321

322322
static void __exit cleanup_slots(void)
323323
{
324-
struct list_head *tmp;
325-
struct list_head *next;
326-
struct slot *slot;
324+
struct slot *slot, *next;
327325

328326
/*
329327
* Unregister all of our slots with the pci_hotplug subsystem.
330328
* Memory will be freed in release_slot() callback after slot's
331329
* lifespan is finished.
332330
*/
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) {
335332
list_del(&slot->slot_list);
336333
pci_hp_deregister(slot->hotplug_slot);
337334
}

‎drivers/pci/hotplug/rpadlpar_core.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,10 @@ static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
114114
*/
115115
static struct slot *find_php_slot(struct device_node *dn)
116116
{
117-
struct list_head *tmp, *n;
118-
struct slot *slot;
117+
struct slot *slot, *next;
119118

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) {
122121
if (slot->dn == dn)
123122
return slot;
124123
}

‎drivers/pci/hotplug/rpaphp_core.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,17 +356,16 @@ EXPORT_SYMBOL_GPL(rpaphp_add_slot);
356356

357357
static void __exit cleanup_slots(void)
358358
{
359-
struct list_head *tmp, *n;
360-
struct slot *slot;
359+
struct slot *slot, *next;
361360

362361
/*
363362
* Unregister all of our slots with the pci_hotplug subsystem,
364363
* and free up all memory that we had allocated.
365364
* memory will be freed in release_slot callback.
366365
*/
367366

368-
list_for_each_safe(tmp, n, &rpaphp_slot_head) {
369-
slot = list_entry(tmp, struct slot, rpaphp_slot_list);
367+
list_for_each_entry_safe(slot, next, &rpaphp_slot_head,
368+
rpaphp_slot_list) {
370369
list_del(&slot->rpaphp_slot_list);
371370
pci_hp_deregister(slot->hotplug_slot);
372371
}

‎drivers/pci/hotplug/s390_pci_hpc.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,10 @@ int zpci_init_slot(struct zpci_dev *zdev)
201201

202202
void zpci_exit_slot(struct zpci_dev *zdev)
203203
{
204-
struct list_head *tmp, *n;
205-
struct slot *slot;
204+
struct slot *slot, *next;
206205

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) {
209208
if (slot->zdev != zdev)
210209
continue;
211210
list_del(&slot->slot_list);

‎drivers/pci/hotplug/shpchp_core.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,9 @@ static int init_slots(struct controller *ctrl)
178178

179179
void cleanup_slots(struct controller *ctrl)
180180
{
181-
struct list_head *tmp;
182-
struct list_head *next;
183-
struct slot *slot;
181+
struct slot *slot, *next;
184182

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) {
187184
list_del(&slot->slot_list);
188185
cancel_delayed_work(&slot->work);
189186
destroy_workqueue(slot->wq);

0 commit comments

Comments
 (0)