ChangeSet 1.1587.12.39, 2004/04/30 14:14:30-07:00, eike-hotplug@sf-tec.de [PATCH] Compaq PCI Hotplug: use goto for error handling in cpqphp_ctrl.c Change cpqphp_ctrl.c to use goto for error handling. drivers/pci/hotplug/cpqphp_ctrl.c | 70 +++++++++++++++----------------------- 1 files changed, 29 insertions(+), 41 deletions(-) diff -Nru a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c --- a/drivers/pci/hotplug/cpqphp_ctrl.c Mon May 17 17:01:53 2004 +++ b/drivers/pci/hotplug/cpqphp_ctrl.c Mon May 17 17:01:53 2004 @@ -519,30 +519,27 @@ kfree(prevnode); } - if (node->length < alignment) { - kfree(node); - return NULL; - } + if (node->length < alignment) + goto error; if (node->base & (alignment - 1)) { /* Short circuit if adjusted size is too small */ temp_dword = (node->base | (alignment-1)) + 1; - if ((node->length - (temp_dword - node->base)) < alignment) { - kfree(node); - return NULL; - } + if ((node->length - (temp_dword - node->base)) < alignment) + goto error; node->length -= (temp_dword - node->base); node->base = temp_dword; } - if (node->length & (alignment - 1)) { + if (node->length & (alignment - 1)) /* There's stuff in use after this node */ - kfree(node); - return NULL; - } + goto error; return node; +error: + kfree(node); + return NULL; } @@ -1082,26 +1079,23 @@ next = cpqhp_slot_list[bridge->bus]; - if (next == NULL) { + if (next == NULL) return 1; - } if (next == bridge) { cpqhp_slot_list[bridge->bus] = bridge->next; - kfree(bridge); - return 0; + goto out; } - while ((next->next != bridge) && (next->next != NULL)) { + while ((next->next != bridge) && (next->next != NULL)) next = next->next; - } - if (next->next == bridge) { - next->next = bridge->next; - kfree(bridge); - return 0; - } else + if (next->next != bridge) return 2; + next->next = bridge->next; +out: + kfree(bridge); + return 0; } @@ -2720,15 +2714,8 @@ } /* End of IF (device in slot?) */ } /* End of FOR loop */ - if (rc) { - cpqhp_destroy_resource_list(&temp_resources); - - return_resource(&(resources->bus_head), hold_bus_node); - return_resource(&(resources->io_head), hold_IO_node); - return_resource(&(resources->mem_head), hold_mem_node); - return_resource(&(resources->p_mem_head), hold_p_mem_node); - return rc; - } + if (rc) + goto free_and_out; /* save the interrupt routing information */ if (resources->irqs) { resources->irqs->interrupt[0] = irqs.interrupt[0]; @@ -2742,15 +2729,8 @@ if (irqs.valid_INT & (0x01 << cloop)) { rc = cpqhp_set_irq(func->bus, func->device, 0x0A + cloop, irqs.interrupt[cloop]); - if (rc) { - cpqhp_destroy_resource_list (&temp_resources); - - return_resource(&(resources-> bus_head), hold_bus_node); - return_resource(&(resources-> io_head), hold_IO_node); - return_resource(&(resources-> mem_head), hold_mem_node); - return_resource(&(resources-> p_mem_head), hold_p_mem_node); - return rc; - } + if (rc) + goto free_and_out; } } /* end of for loop */ } @@ -3131,4 +3111,12 @@ func->configured = 1; return 0; +free_and_out: + cpqhp_destroy_resource_list (&temp_resources); + + return_resource(&(resources-> bus_head), hold_bus_node); + return_resource(&(resources-> io_head), hold_IO_node); + return_resource(&(resources-> mem_head), hold_mem_node); + return_resource(&(resources-> p_mem_head), hold_p_mem_node); + return rc; }