<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">ChangeSet 1.1587.12.71, 2004/04/30 15:23:11-07:00, eike-hotplug@sf-tec.de

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

Convert shpchp_core.c::init_slots to use goto for error handling.


 drivers/pci/hotplug/shpchp_core.c |   53 +++++++++++++++++---------------------
 1 files changed, 24 insertions(+), 29 deletions(-)


diff -Nru a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
--- a/drivers/pci/hotplug/shpchp_core.c	Mon May 17 16:58:29 2004
+++ b/drivers/pci/hotplug/shpchp_core.c	Mon May 17 16:58:29 2004
@@ -112,7 +112,7 @@
 	u8 number_of_slots;
 	u8 slot_device;
 	u32 slot_number, sun;
-	int result;
+	int result = -ENOMEM;
 
 	dbg("%s\n",__FUNCTION__);
 
@@ -123,30 +123,21 @@
 	while (number_of_slots) {
 		new_slot = (struct slot *) kmalloc(sizeof(struct slot), GFP_KERNEL);
 		if (!new_slot)
-			return -ENOMEM;
+			goto error;
 
 		memset(new_slot, 0, sizeof(struct slot));
 		new_slot-&gt;hotplug_slot = kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL);
-		if (!new_slot-&gt;hotplug_slot) {
-			kfree (new_slot);
-			return -ENOMEM;
-		}
+		if (!new_slot-&gt;hotplug_slot)
+			goto error_slot;
 		memset(new_slot-&gt;hotplug_slot, 0, sizeof (struct hotplug_slot));
 
 		new_slot-&gt;hotplug_slot-&gt;info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL);
-		if (!new_slot-&gt;hotplug_slot-&gt;info) {
-			kfree (new_slot-&gt;hotplug_slot);
-			kfree (new_slot);
-			return -ENOMEM;
-		}
+		if (!new_slot-&gt;hotplug_slot-&gt;info)
+			goto error_hpslot;
 		memset(new_slot-&gt;hotplug_slot-&gt;info, 0, sizeof (struct hotplug_slot_info));
 		new_slot-&gt;hotplug_slot-&gt;name = kmalloc (SLOT_NAME_SIZE, GFP_KERNEL);
-		if (!new_slot-&gt;hotplug_slot-&gt;name) {
-			kfree (new_slot-&gt;hotplug_slot-&gt;info);
-			kfree (new_slot-&gt;hotplug_slot);
-			kfree (new_slot);
-			return -ENOMEM;
-		}
+		if (!new_slot-&gt;hotplug_slot-&gt;name)
+			goto error_info;
 
 		new_slot-&gt;magic = SLOT_MAGIC;
 		new_slot-&gt;ctrl = ctrl;
@@ -154,20 +145,17 @@
 		new_slot-&gt;device = slot_device;
 		new_slot-&gt;hpc_ops = ctrl-&gt;hpc_ops;
 
-		if (shpchprm_get_physical_slot_number(ctrl, &amp;sun, new_slot-&gt;bus, new_slot-&gt;device)) {
-			kfree (new_slot-&gt;hotplug_slot-&gt;info);
-			kfree (new_slot-&gt;hotplug_slot);
-			kfree (new_slot);
-			return -ENOMEM;
-		}
+		if (shpchprm_get_physical_slot_number(ctrl, &amp;sun,
+					new_slot-&gt;bus, new_slot-&gt;device))
+			goto error_name;
 
 		new_slot-&gt;number = sun;
 		new_slot-&gt;hp_slot = slot_device - ctrl-&gt;slot_device_offset;
 
 		/* register this slot with the hotplug pci core */
 		new_slot-&gt;hotplug_slot-&gt;private = new_slot;
-		make_slot_name(new_slot-&gt;hotplug_slot-&gt;name, SLOT_NAME_SIZE, new_slot);
 		new_slot-&gt;hotplug_slot-&gt;release = &amp;release_slot;
+		make_slot_name(new_slot-&gt;hotplug_slot-&gt;name, SLOT_NAME_SIZE, new_slot);
 		new_slot-&gt;hotplug_slot-&gt;ops = &amp;shpchp_hotplug_slot_ops;
 
 		new_slot-&gt;hpc_ops-&gt;get_power_status(new_slot, &amp;(new_slot-&gt;hotplug_slot-&gt;info-&gt;power_status));
@@ -180,11 +168,7 @@
 		result = pci_hp_register (new_slot-&gt;hotplug_slot);
 		if (result) {
 			err ("pci_hp_register failed with error %d\n", result);
-			kfree (new_slot-&gt;hotplug_slot-&gt;info);
-			kfree (new_slot-&gt;hotplug_slot-&gt;name);
-			kfree (new_slot-&gt;hotplug_slot);
-			kfree (new_slot);
-			return result;
+			goto error_name;
 		}
 
 		new_slot-&gt;next = ctrl-&gt;slot;
@@ -196,6 +180,17 @@
 	}
 
 	return 0;
+
+error_name:
+	kfree(new_slot-&gt;hotplug_slot-&gt;name);
+error_info:
+	kfree(new_slot-&gt;hotplug_slot-&gt;info);
+error_hpslot:
+	kfree(new_slot-&gt;hotplug_slot);
+error_slot:
+	kfree(new_slot);
+error:
+	return result;
 }
 
 static void cleanup_slots(const struct controller *ctrl)
</pre></body></html>