<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.39, 2004/04/30 14:14:30-07:00, eike-hotplug@sf-tec.de

[PATCH] Compaq PCI Hotplug: use goto for error handling in cpqphp_ctrl.c

Change cpqphp_ctrl.c to use goto for error handling.


 drivers/pci/hotplug/cpqphp_ctrl.c |   70 +++++++++++++++-----------------------
 1 files changed, 29 insertions(+), 41 deletions(-)


diff -Nru a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
--- a/drivers/pci/hotplug/cpqphp_ctrl.c	Mon May 17 17:01:53 2004
+++ b/drivers/pci/hotplug/cpqphp_ctrl.c	Mon May 17 17:01:53 2004
@@ -519,30 +519,27 @@
 		kfree(prevnode);
 	}
 
-	if (node-&gt;length &lt; alignment) {
-		kfree(node);
-		return NULL;
-	}
+	if (node-&gt;length &lt; alignment)
+		goto error;
 
 	if (node-&gt;base &amp; (alignment - 1)) {
 		/* Short circuit if adjusted size is too small */
 		temp_dword = (node-&gt;base | (alignment-1)) + 1;
-		if ((node-&gt;length - (temp_dword - node-&gt;base)) &lt; alignment) {
-			kfree(node);
-			return NULL;
-		}
+		if ((node-&gt;length - (temp_dword - node-&gt;base)) &lt; alignment)
+			goto error;
 
 		node-&gt;length -= (temp_dword - node-&gt;base);
 		node-&gt;base = temp_dword;
 	}
 
-	if (node-&gt;length &amp; (alignment - 1)) {
+	if (node-&gt;length &amp; (alignment - 1))
 		/* There's stuff in use after this node */
-		kfree(node);
-		return NULL;
-	}
+		goto error;
 
 	return node;
+error:
+	kfree(node);
+	return NULL;
 }
 
 
@@ -1082,26 +1079,23 @@
 
 	next = cpqhp_slot_list[bridge-&gt;bus];
 
-	if (next == NULL) {
+	if (next == NULL)
 		return 1;
-	}
 
 	if (next == bridge) {
 		cpqhp_slot_list[bridge-&gt;bus] = bridge-&gt;next;
-		kfree(bridge);
-		return 0;
+		goto out;
 	}
 
-	while ((next-&gt;next != bridge) &amp;&amp; (next-&gt;next != NULL)) {
+	while ((next-&gt;next != bridge) &amp;&amp; (next-&gt;next != NULL))
 		next = next-&gt;next;
-	}
 
-	if (next-&gt;next == bridge) {
-		next-&gt;next = bridge-&gt;next;
-		kfree(bridge);
-		return 0;
-	} else
+	if (next-&gt;next != bridge)
 		return 2;
+	next-&gt;next = bridge-&gt;next;
+out:
+	kfree(bridge);
+	return 0;
 }
 
 
@@ -2720,15 +2714,8 @@
 			}	/* End of IF (device in slot?) */
 		}		/* End of FOR loop */
 
-		if (rc) {
-			cpqhp_destroy_resource_list(&amp;temp_resources);
-
-			return_resource(&amp;(resources-&gt;bus_head), hold_bus_node);
-			return_resource(&amp;(resources-&gt;io_head), hold_IO_node);
-			return_resource(&amp;(resources-&gt;mem_head), hold_mem_node);
-			return_resource(&amp;(resources-&gt;p_mem_head), hold_p_mem_node);
-			return rc;
-		}
+		if (rc)
+			goto free_and_out;
 		/* save the interrupt routing information */
 		if (resources-&gt;irqs) {
 			resources-&gt;irqs-&gt;interrupt[0] = irqs.interrupt[0];
@@ -2742,15 +2729,8 @@
 				if (irqs.valid_INT &amp; (0x01 &lt;&lt; cloop)) {
 					rc = cpqhp_set_irq(func-&gt;bus, func-&gt;device,
 							   0x0A + cloop, irqs.interrupt[cloop]);
-					if (rc) {
-						cpqhp_destroy_resource_list (&amp;temp_resources);
-
-						return_resource(&amp;(resources-&gt; bus_head), hold_bus_node);
-						return_resource(&amp;(resources-&gt; io_head), hold_IO_node);
-						return_resource(&amp;(resources-&gt; mem_head), hold_mem_node);
-						return_resource(&amp;(resources-&gt; p_mem_head), hold_p_mem_node);
-						return rc;
-					}
+					if (rc)
+						goto free_and_out;
 				}
 			}	/* end of for loop */
 		}
@@ -3131,4 +3111,12 @@
 	func-&gt;configured = 1;
 
 	return 0;
+free_and_out:
+	cpqhp_destroy_resource_list (&amp;temp_resources);
+
+	return_resource(&amp;(resources-&gt; bus_head), hold_bus_node);
+	return_resource(&amp;(resources-&gt; io_head), hold_IO_node);
+	return_resource(&amp;(resources-&gt; mem_head), hold_mem_node);
+	return_resource(&amp;(resources-&gt; p_mem_head), hold_p_mem_node);
+	return rc;
 }
</pre></body></html>