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

[PATCH] PCI Hotplug skeleton: use goto for error handling

Convert PCI hotplug skeleton driver to use goto for error handling in
init_slots to avoid code duplication.
parent ebf2a656
...@@ -251,7 +251,7 @@ static int __init init_slots(void) ...@@ -251,7 +251,7 @@ static int __init init_slots(void)
struct hotplug_slot *hotplug_slot; struct hotplug_slot *hotplug_slot;
struct hotplug_slot_info *info; struct hotplug_slot_info *info;
char *name; char *name;
int retval = 0; int retval = -ENOMEM;
int i; int i;
/* /*
...@@ -261,33 +261,24 @@ static int __init init_slots(void) ...@@ -261,33 +261,24 @@ 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));
hotplug_slot = kmalloc(sizeof (struct hotplug_slot), GFP_KERNEL); hotplug_slot = kmalloc(sizeof (struct hotplug_slot), GFP_KERNEL);
if (!hotplug_slot) { if (!hotplug_slot)
kfree (slot); goto error_slot;
return -ENOMEM;
}
memset(hotplug_slot, 0, sizeof (struct hotplug_slot)); memset(hotplug_slot, 0, sizeof (struct hotplug_slot));
slot->hotplug_slot = hotplug_slot; slot->hotplug_slot = hotplug_slot;
info = kmalloc(sizeof (struct hotplug_slot_info), GFP_KERNEL); info = kmalloc(sizeof (struct hotplug_slot_info), GFP_KERNEL);
if (!info) { if (!info)
kfree (hotplug_slot); goto error_hpslot;
kfree (slot);
return -ENOMEM;
}
memset(info, 0, sizeof (struct hotplug_slot_info)); memset(info, 0, sizeof (struct hotplug_slot_info));
hotplug_slot->info = info; hotplug_slot->info = info;
name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
if (!name) { if (!name)
kfree (info); goto error_info;
kfree (hotplug_slot);
kfree (slot);
return -ENOMEM;
}
hotplug_slot->name = name; hotplug_slot->name = name;
slot->number = i; slot->number = i;
...@@ -310,17 +301,23 @@ static int __init init_slots(void) ...@@ -310,17 +301,23 @@ static int __init init_slots(void)
retval = pci_hp_register(slot->hotplug_slot); retval = pci_hp_register(slot->hotplug_slot);
if (retval) { if (retval) {
err("pci_hp_register failed with error %d\n", retval); err("pci_hp_register failed with error %d\n", retval);
kfree (info); goto error_name;
kfree (name);
kfree (hotplug_slot);
kfree (slot);
return retval;
} }
/* add slot to our internal list */ /* add slot to our internal list */
list_add (&slot->slot_list, &slot_list); list_add (&slot->slot_list, &slot_list);
} }
return 0;
error_name:
kfree(name);
error_info:
kfree(info);
error_hpslot:
kfree(hotplug_slot);
error_slot:
kfree(slot);
error:
return retval; return retval;
} }
......
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