aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband
diff options
context:
space:
mode:
authorRoland Dreier <rolandd@cisco.com>2008-10-14 17:05:36 -0400
committerRoland Dreier <rolandd@cisco.com>2008-10-14 17:05:36 -0400
commit528051746b24dd214883db11bcbb0e667f60447d (patch)
tree4b9a761c73aa26a8767de61e17ff10072f4b32c6 /drivers/infiniband
parentf6bccf695431da0e9bd773550ae91b8cb9ffb227 (diff)
IB/mad: Use krealloc() to resize snoop table
Use krealloc() instead of kmalloc() followed by memcpy() when resizing the MAD module's snoop table. Also put parentheses around the new table size to avoid calculating the wrong size to allocate, which fixes a bug pointed out by Haven Hash <haven.hash@isilon.com>. Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r--drivers/infiniband/core/mad.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index 49c45feccd5b..5c54fc2350be 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -406,19 +406,15 @@ static int register_snoop_agent(struct ib_mad_qp_info *qp_info,
406 406
407 if (i == qp_info->snoop_table_size) { 407 if (i == qp_info->snoop_table_size) {
408 /* Grow table. */ 408 /* Grow table. */
409 new_snoop_table = kmalloc(sizeof mad_snoop_priv * 409 new_snoop_table = krealloc(qp_info->snoop_table,
410 qp_info->snoop_table_size + 1, 410 sizeof mad_snoop_priv *
411 GFP_ATOMIC); 411 (qp_info->snoop_table_size + 1),
412 GFP_ATOMIC);
412 if (!new_snoop_table) { 413 if (!new_snoop_table) {
413 i = -ENOMEM; 414 i = -ENOMEM;
414 goto out; 415 goto out;
415 } 416 }
416 if (qp_info->snoop_table) { 417
417 memcpy(new_snoop_table, qp_info->snoop_table,
418 sizeof mad_snoop_priv *
419 qp_info->snoop_table_size);
420 kfree(qp_info->snoop_table);
421 }
422 qp_info->snoop_table = new_snoop_table; 418 qp_info->snoop_table = new_snoop_table;
423 qp_info->snoop_table_size++; 419 qp_info->snoop_table_size++;
424 } 420 }