[openib-general] [PATCH] General cleanup in add_mad_reg_req
Krishna Kumar
krkumar at us.ibm.com
Tue Nov 2 11:17:25 PST 2004
Optimize a "clear" operation to use memset, and re-arrange the code a bit
to make the function cleaner.
(Hal, I am sending patches based on latest bits, but not on top of my
earlier sent-but-not-applied patches. If it doesn't apply, please let me
know and I will recreate the patch).
Thanks.
- KK
diff -ruNp 1/mad.c 2/mad.c
--- 1/mad.c 2004-11-02 10:46:19.000000000 -0800
+++ 2/mad.c 2004-11-02 10:58:50.000000000 -0800
@@ -596,31 +596,28 @@ static int add_mad_reg_req(struct ib_mad
if (!*class) {
printk(KERN_ERR PFX "No memory for "
"ib_mad_mgmt_class_table\n");
+ ret = -ENOMEM;
goto error1;
}
/* Clear management class table for this class version */
- for (i = 0; i < MAX_MGMT_CLASS; i++) {
- (*class)->method_table[i] = NULL;
- }
+ memset((*class)->method_table, 0,
+ sizeof((*class)->method_table));
/* Allocate method table for this management class */
method = &(*class)->method_table[mgmt_class];
- if (allocate_method_table(method)) {
+ if ((ret = allocate_method_table(method)))
goto error2;
- }
} else {
method = &(*class)->method_table[mgmt_class];
if (!*method) {
/* Allocate method table for this management class */
- if (allocate_method_table(method)) {
+ if ((ret = allocate_method_table(method)))
goto error1;
- }
}
}
/* Now, make sure methods are not already in use */
- if (method_in_use(method, mad_reg_req)) {
+ if (method_in_use(method, mad_reg_req))
goto error3;
- }
/* Finally, add in methods being registered */
for (i = find_first_bit(mad_reg_req->method_mask, IB_MGMT_MAX_METHODS);
@@ -641,13 +638,11 @@ error3:
*method = NULL;
}
ret = -EINVAL;
- goto error;
+ goto error1;
error2:
kfree(*class);
*class = NULL;
error1:
- ret = -ENOMEM;
-error:
return ret;
}
More information about the general
mailing list