Commit feed13cd authored by Rolf Eike Beer's avatar Rolf Eike Beer Committed by Deepak Saxena

[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.
parent 9a8c14f8
...@@ -96,7 +96,7 @@ static int init_slots(struct controller *ctrl) ...@@ -96,7 +96,7 @@ static int init_slots(struct controller *ctrl)
u8 number_of_slots; u8 number_of_slots;
u8 slot_device; u8 slot_device;
u32 slot_number; u32 slot_number;
int result; int result = -ENOMEM;
dbg("%s\n",__FUNCTION__); dbg("%s\n",__FUNCTION__);
...@@ -107,32 +107,22 @@ static int init_slots(struct controller *ctrl) ...@@ -107,32 +107,22 @@ static int init_slots(struct controller *ctrl)
while (number_of_slots) { while (number_of_slots) {
new_slot = (struct slot *) kmalloc(sizeof(struct slot), GFP_KERNEL); new_slot = (struct slot *) kmalloc(sizeof(struct slot), GFP_KERNEL);
if (!new_slot) if (!new_slot)
return -ENOMEM; goto error;
memset(new_slot, 0, sizeof(struct slot)); memset(new_slot, 0, sizeof(struct slot));
new_slot->hotplug_slot = kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL); new_slot->hotplug_slot = kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL);
if (!new_slot->hotplug_slot) { if (!new_slot->hotplug_slot)
kfree (new_slot); goto error_slot;
return -ENOMEM;
}
memset(new_slot->hotplug_slot, 0, sizeof (struct hotplug_slot)); memset(new_slot->hotplug_slot, 0, sizeof (struct hotplug_slot));
new_slot->hotplug_slot->info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL); new_slot->hotplug_slot->info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL);
if (!new_slot->hotplug_slot->info) { if (!new_slot->hotplug_slot->info)
kfree (new_slot->hotplug_slot); goto error_hpslot;
kfree (new_slot);
return -ENOMEM;
}
memset(new_slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info)); memset(new_slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info));
new_slot->hotplug_slot->name = kmalloc (SLOT_NAME_SIZE, GFP_KERNEL); new_slot->hotplug_slot->name = kmalloc (SLOT_NAME_SIZE, GFP_KERNEL);
if (!new_slot->hotplug_slot->name) { if (!new_slot->hotplug_slot->name)
kfree (new_slot->hotplug_slot->info); goto error_info;
kfree (new_slot->hotplug_slot);
kfree (new_slot);
return -ENOMEM;
}
new_slot->magic = SLOT_MAGIC;
new_slot->ctrl = ctrl; new_slot->ctrl = ctrl;
new_slot->bus = ctrl->slot_bus; new_slot->bus = ctrl->slot_bus;
new_slot->device = slot_device; new_slot->device = slot_device;
...@@ -156,11 +146,7 @@ static int init_slots(struct controller *ctrl) ...@@ -156,11 +146,7 @@ static int init_slots(struct controller *ctrl)
result = pci_hp_register (new_slot->hotplug_slot); result = pci_hp_register (new_slot->hotplug_slot);
if (result) { if (result) {
err ("pci_hp_register failed with error %d\n", result); err ("pci_hp_register failed with error %d\n", result);
kfree (new_slot->hotplug_slot->info); goto error_name;
kfree (new_slot->hotplug_slot->name);
kfree (new_slot->hotplug_slot);
kfree (new_slot);
return result;
} }
new_slot->next = ctrl->slot; new_slot->next = ctrl->slot;
...@@ -171,7 +157,18 @@ static int init_slots(struct controller *ctrl) ...@@ -171,7 +157,18 @@ static int init_slots(struct controller *ctrl)
slot_number += ctrl->slot_num_inc; 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;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment