ChangeSet 1.1587.12.54, 2004/04/30 14:50:28-07:00, eike-hotplug@sf-tec.de [PATCH] PCI Express Hotplug: use goto for error handling This changes pciehp_core.c::init_slots to use goto for error hanling. Also a missing magic missed by previous patches is killed. drivers/pci/hotplug/pciehp_core.c | 45 +++++++++++++++++--------------------- 1 files changed, 21 insertions(+), 24 deletions(-) diff -Nru a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c --- a/drivers/pci/hotplug/pciehp_core.c Mon May 17 17:00:28 2004 +++ b/drivers/pci/hotplug/pciehp_core.c Mon May 17 17:00:28 2004 @@ -96,7 +96,7 @@ u8 number_of_slots; u8 slot_device; u32 slot_number; - int result; + int result = -ENOMEM; dbg("%s\n",__FUNCTION__); @@ -107,32 +107,22 @@ while (number_of_slots) { new_slot = (struct slot *) kmalloc(sizeof(struct slot), GFP_KERNEL); if (!new_slot) - return -ENOMEM; + goto error; memset(new_slot, 0, sizeof(struct slot)); new_slot->hotplug_slot = kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL); - if (!new_slot->hotplug_slot) { - kfree (new_slot); - return -ENOMEM; - } + if (!new_slot->hotplug_slot) + goto error_slot; memset(new_slot->hotplug_slot, 0, sizeof (struct hotplug_slot)); new_slot->hotplug_slot->info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL); - if (!new_slot->hotplug_slot->info) { - kfree (new_slot->hotplug_slot); - kfree (new_slot); - return -ENOMEM; - } + if (!new_slot->hotplug_slot->info) + goto error_hpslot; memset(new_slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info)); new_slot->hotplug_slot->name = kmalloc (SLOT_NAME_SIZE, GFP_KERNEL); - if (!new_slot->hotplug_slot->name) { - kfree (new_slot->hotplug_slot->info); - kfree (new_slot->hotplug_slot); - kfree (new_slot); - return -ENOMEM; - } + if (!new_slot->hotplug_slot->name) + goto error_info; - new_slot->magic = SLOT_MAGIC; new_slot->ctrl = ctrl; new_slot->bus = ctrl->slot_bus; new_slot->device = slot_device; @@ -156,11 +146,7 @@ result = pci_hp_register (new_slot->hotplug_slot); if (result) { err ("pci_hp_register failed with error %d\n", result); - kfree (new_slot->hotplug_slot->info); - kfree (new_slot->hotplug_slot->name); - kfree (new_slot->hotplug_slot); - kfree (new_slot); - return result; + goto error_name; } new_slot->next = ctrl->slot; @@ -171,7 +157,18 @@ slot_number += ctrl->slot_num_inc; } - return(0); + return 0; + +error_name: + kfree(new_slot->hotplug_slot->name); +error_info: + kfree(new_slot->hotplug_slot->info); +error_hpslot: + kfree(new_slot->hotplug_slot); +error_slot: + kfree(new_slot); +error: + return result; }