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

[PATCH] PCI Hotplug: Clean up acpiphp_core.c: use goto for error handling

This one converts the error handling in init_slots to use gotos to avoid code
duplication.
parent b77abdc7
...@@ -324,31 +324,22 @@ static int __init init_slots(void) ...@@ -324,31 +324,22 @@ static int __init init_slots(void)
for (i = 0; i < num_slots; ++i) { for (i = 0; i < num_slots; ++i) {
slot = kmalloc(sizeof(struct slot), GFP_KERNEL); slot = kmalloc(sizeof(struct slot), GFP_KERNEL);
if (!slot) if (!slot)
return -ENOMEM; goto error;
memset(slot, 0, sizeof(struct slot)); memset(slot, 0, sizeof(struct slot));
slot->hotplug_slot = kmalloc(sizeof(struct hotplug_slot), GFP_KERNEL); slot->hotplug_slot = kmalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
if (!slot->hotplug_slot) { if (!slot->hotplug_slot)
kfree(slot); goto error_slot;
return -ENOMEM;
}
memset(slot->hotplug_slot, 0, sizeof(struct hotplug_slot)); memset(slot->hotplug_slot, 0, sizeof(struct hotplug_slot));
slot->hotplug_slot->info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); slot->hotplug_slot->info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
if (!slot->hotplug_slot->info) { if (!slot->hotplug_slot->info)
kfree(slot->hotplug_slot); goto error_hpslot;
kfree(slot);
return -ENOMEM;
}
memset(slot->hotplug_slot->info, 0, sizeof(struct hotplug_slot_info)); memset(slot->hotplug_slot->info, 0, sizeof(struct hotplug_slot_info));
slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
if (!slot->hotplug_slot->name) { if (!slot->hotplug_slot->name)
kfree(slot->hotplug_slot->info); goto error_info;
kfree(slot->hotplug_slot);
kfree(slot);
return -ENOMEM;
}
slot->magic = SLOT_MAGIC; slot->magic = SLOT_MAGIC;
slot->number = i; slot->number = i;
...@@ -378,6 +369,14 @@ static int __init init_slots(void) ...@@ -378,6 +369,14 @@ static int __init init_slots(void)
} }
return retval; return retval;
error_info:
kfree(slot->hotplug_slot->info);
error_hpslot:
kfree(slot->hotplug_slot);
error_slot:
kfree(slot);
error:
return -ENOMEM;
} }
......
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