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

[PATCH] CompactPCI: use goto for error handling

Convert cpci_hotplug_core.c::cpci_hp_register_bus to use goto for error
handling.

Eike
parent c1600f7c
...@@ -287,7 +287,7 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last) ...@@ -287,7 +287,7 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
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 status = 0; int status = -ENOMEM;
int i; int i;
if(!(controller && bus)) { if(!(controller && bus)) {
...@@ -300,35 +300,26 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last) ...@@ -300,35 +300,26 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
*/ */
for (i = first; i <= last; ++i) { for (i = first; i <= last; ++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 = hotplug_slot =
kmalloc(sizeof (struct hotplug_slot), GFP_KERNEL); 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->bus = bus; slot->bus = bus;
...@@ -350,13 +341,9 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last) ...@@ -350,13 +341,9 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
dbg("registering slot %s", slot->hotplug_slot->name); dbg("registering slot %s", slot->hotplug_slot->name);
status = pci_hp_register(slot->hotplug_slot); status = pci_hp_register(slot->hotplug_slot);
if(status) { if (status) {
err("pci_hp_register failed with error %d", status); err("pci_hp_register failed with error %d", status);
kfree(info); goto error_name;
kfree(name);
kfree(hotplug_slot);
kfree(slot);
return status;
} }
/* Add slot to our internal list */ /* Add slot to our internal list */
...@@ -365,6 +352,16 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last) ...@@ -365,6 +352,16 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
slots++; slots++;
spin_unlock(&list_lock); spin_unlock(&list_lock);
} }
return 0;
error_name:
kfree(name);
error_info:
kfree(info);
error_hpslot:
kfree(hotplug_slot);
error_slot:
kfree(slot);
error:
return status; return status;
} }
...@@ -864,7 +861,6 @@ cpci_hotplug_exit(void) ...@@ -864,7 +861,6 @@ cpci_hotplug_exit(void)
cleanup_slots(); cleanup_slots();
} }
EXPORT_SYMBOL_GPL(cpci_hp_register_controller); EXPORT_SYMBOL_GPL(cpci_hp_register_controller);
EXPORT_SYMBOL_GPL(cpci_hp_unregister_controller); EXPORT_SYMBOL_GPL(cpci_hp_unregister_controller);
EXPORT_SYMBOL_GPL(cpci_hp_register_bus); EXPORT_SYMBOL_GPL(cpci_hp_register_bus);
......
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