ChangeSet 1.1587.12.10, 2004/04/29 14:25:00-07:00, eike-hotplug@sf-tec.de

[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.


 drivers/pci/hotplug/acpiphp_core.c |   31 +++++++++++++++----------------
 1 files changed, 15 insertions(+), 16 deletions(-)


diff -Nru a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
--- a/drivers/pci/hotplug/acpiphp_core.c	Mon May 17 17:07:38 2004
+++ b/drivers/pci/hotplug/acpiphp_core.c	Mon May 17 17:07:38 2004
@@ -324,31 +324,22 @@
 	for (i = 0; i < num_slots; ++i) {
 		slot = kmalloc(sizeof(struct slot), GFP_KERNEL);
 		if (!slot)
-			return -ENOMEM;
+			goto error;
 		memset(slot, 0, sizeof(struct slot));
 
 		slot->hotplug_slot = kmalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
-		if (!slot->hotplug_slot) {
-			kfree(slot);
-			return -ENOMEM;
-		}
+		if (!slot->hotplug_slot)
+			goto error_slot;
 		memset(slot->hotplug_slot, 0, sizeof(struct hotplug_slot));
 
 		slot->hotplug_slot->info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
-		if (!slot->hotplug_slot->info) {
-			kfree(slot->hotplug_slot);
-			kfree(slot);
-			return -ENOMEM;
-		}
+		if (!slot->hotplug_slot->info)
+			goto error_hpslot;
 		memset(slot->hotplug_slot->info, 0, sizeof(struct hotplug_slot_info));
 
 		slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
-		if (!slot->hotplug_slot->name) {
-			kfree(slot->hotplug_slot->info);
-			kfree(slot->hotplug_slot);
-			kfree(slot);
-			return -ENOMEM;
-		}
+		if (!slot->hotplug_slot->name)
+			goto error_info;
 
 		slot->magic = SLOT_MAGIC;
 		slot->number = i;
@@ -378,6 +369,14 @@
 	}
 
 	return retval;
+error_info:
+	kfree(slot->hotplug_slot->info);
+error_hpslot:
+	kfree(slot->hotplug_slot);
+error_slot:
+	kfree(slot);
+error:
+	return -ENOMEM;
 }
 
 
