[openib-general] [PATCH] code/stack cleanup in find_mad_agent/validate_mad routines

Sean Hefty mshefty at ichips.intel.com
Thu Sep 30 12:54:14 PDT 2004


Patch removes a couple of stack variables, eliminates gotos, and reformats lines over 80 columns.

- Sean

-- 
Index: access/ib_mad.c
===================================================================
--- access/ib_mad.c	(revision 915)
+++ access/ib_mad.c	(working copy)
@@ -670,7 +670,7 @@
 						   struct ib_mad *mad,
 						   int solicited)
 {
-	struct ib_mad_agent_private *entry, *mad_agent = NULL;
+	struct ib_mad_agent_private *entry;
 	struct ib_mad_mgmt_class_table *version;
 	struct ib_mad_mgmt_method_table *class;
 	u32 hi_tid;
@@ -680,64 +680,52 @@
 		/* Routing is based on high 32 bits of transaction ID of MAD  */
 		hi_tid = mad->mad_hdr.tid >> 32;
 		list_for_each_entry(entry, &port_priv->agent_list, agent_list) {
-			if (entry->agent.hi_tid == hi_tid) {
-				mad_agent = entry;
-				break;
-			}
-		}
-		if (!mad_agent) {
-			printk(KERN_ERR "No client 0x%x for received MAD\n",
-			       (u32)(mad->mad_hdr.tid >> 32));
-			goto ret;
+			if (entry->agent.hi_tid == hi_tid)
+				return entry;
 		}
+		printk(KERN_NOTICE "No client 0x%x for received MAD\n", hi_tid);
 	} else {
 		/* Routing is based on version, class, and method */
 		if (mad->mad_hdr.class_version >= MAX_MGMT_VERSION) {
-			printk(KERN_ERR "MAD received with unsupported class version %d\n",
-			       mad->mad_hdr.class_version);
-			goto ret;
+			printk(KERN_ERR "MAD received with unsupported class "
+			       "version %d\n", mad->mad_hdr.class_version);
+			return NULL;
 		}
 		version = port_priv->version[mad->mad_hdr.class_version];
 		if (!version) {
-			printk(KERN_ERR "MAD received for class version %d with no client\n", mad->mad_hdr.class_version);
-			goto ret;
+			printk(KERN_ERR "MAD received for class version %d "
+			       "with no client\n", mad->mad_hdr.class_version);
+			return NULL;
 		}
-		class = version->method_table[convert_mgmt_class(mad->mad_hdr.mgmt_class)];	
+		class = version->method_table[
+			convert_mgmt_class(mad->mad_hdr.mgmt_class)];	
 		if (!class) {
-			printk(KERN_ERR "MAD receive for class %d with no client\n", mad->mad_hdr.mgmt_class);
-			goto ret;
+			printk(KERN_ERR "MAD receive for class %d with no "
+			       "client\n", mad->mad_hdr.mgmt_class);
+			return NULL;
 		}
-		mad_agent = class->agent[mad->mad_hdr.method & ~IB_MGMT_METHOD_RESP];		
+		return class->agent[mad->mad_hdr.method & ~IB_MGMT_METHOD_RESP];		
 	}
-
-ret:
-	return mad_agent;
+	return NULL;
 }
 
 static int validate_mad(struct ib_mad *mad, u32 qp_num)
 {
-	int valid = 0;
-
 	/* Make sure MAD base version is understood */
 	if (mad->mad_hdr.base_version != IB_MGMT_BASE_VERSION) {
-		printk(KERN_ERR "MAD received with unsupported base version %d\n",
-		       mad->mad_hdr.base_version);
-		goto ret;
+		printk(KERN_ERR "MAD received with unsupported base "
+		       "version %d\n", mad->mad_hdr.base_version);
+		return 0;
 	}
 
 	/* Filter SMI packets sent to other than QP0 */
 	if ((mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED) ||
 	    (mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)) {
-		if (qp_num == 0)
-			valid = 1;
+		return (qp_num == 0);
 	} else {
 		/* Filter GSI packets sent to QP0 */
-		if (qp_num != 0)
-			valid = 1;	
+		return (qp_num != 0);
 	}
-
-ret:
-	return valid;
 }
 
 static void ib_mad_recv_done_handler(struct ib_mad_port_private *port_priv,



More information about the general mailing list