[openib-general] [PATCH] ib_smi: Centralized error exiting in ib_smi_port_open

Hal Rosenstock halr at voltaire.com
Fri Oct 8 06:25:12 PDT 2004


ib_smi: Centralized error exiting in ib_smi_port_open

Index: ib_smi.c
===================================================================
--- ib_smi.c	(revision 958)
+++ ib_smi.c	(working copy)
@@ -536,7 +536,8 @@
 	port_priv = kmalloc(sizeof *port_priv, GFP_KERNEL);
 	if (!port_priv) {
 		printk(KERN_ERR "No memory for ib_smi_port_private\n");
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto error1;
 	}
 
 	memset(port_priv, 0, sizeof *port_priv);
@@ -564,8 +565,7 @@
 						     NULL);
 	if (IS_ERR(port_priv->mad_agent)) {
 		ret = PTR_ERR(port_priv->mad_agent);
-		kfree(port_priv);
-		return ret;
+		goto error2;
 	}
 
 	/* Obtain MAD agent for LID routed SM class */
@@ -578,9 +578,7 @@
 						      NULL);
 	if (IS_ERR(port_priv->mad_agent2)) {
 		ret = PTR_ERR(port_priv->mad_agent2);
-		ib_unregister_mad_agent(port_priv->mad_agent);
-		kfree(port_priv);
-		return ret;
+		goto error3;
 	}
 
 	port_priv->mr = ib_reg_phys_mr(port_priv->mad_agent->qp->pd,
@@ -588,11 +586,8 @@
 				       IB_ACCESS_LOCAL_WRITE, &iova);
 	if (IS_ERR(port_priv->mr)) {
 		printk(KERN_ERR "Couldn't register MR\n");
-		ib_unregister_mad_agent(port_priv->mad_agent2);
-		ib_unregister_mad_agent(port_priv->mad_agent);	
 		ret = PTR_ERR(port_priv->mr);
-		kfree(port_priv);
-		return ret;
+		goto error4;
 	} 
 
 	spin_lock_irqsave(&ib_smi_port_list_lock, flags);
@@ -600,6 +595,15 @@
 	spin_unlock_irqrestore(&ib_smi_port_list_lock, flags);
 
 	return 0;
+
+error4:
+	ib_unregister_mad_agent(port_priv->mad_agent2);
+error3:
+	ib_unregister_mad_agent(port_priv->mad_agent);
+error2:
+	kfree(port_priv);
+error1:
+	return ret;
 }
 
 static int ib_smi_port_close(struct ib_device *device, int port_num)






More information about the general mailing list