mirror of https://gitee.com/openkylin/linux.git
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>
This commit is contained in:
parent
f6bccf6954
commit
528051746b
|
@ -406,19 +406,15 @@ static int register_snoop_agent(struct ib_mad_qp_info *qp_info,
|
||||||
|
|
||||||
if (i == qp_info->snoop_table_size) {
|
if (i == qp_info->snoop_table_size) {
|
||||||
/* Grow table. */
|
/* Grow table. */
|
||||||
new_snoop_table = kmalloc(sizeof mad_snoop_priv *
|
new_snoop_table = krealloc(qp_info->snoop_table,
|
||||||
qp_info->snoop_table_size + 1,
|
sizeof mad_snoop_priv *
|
||||||
GFP_ATOMIC);
|
(qp_info->snoop_table_size + 1),
|
||||||
|
GFP_ATOMIC);
|
||||||
if (!new_snoop_table) {
|
if (!new_snoop_table) {
|
||||||
i = -ENOMEM;
|
i = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (qp_info->snoop_table) {
|
|
||||||
memcpy(new_snoop_table, qp_info->snoop_table,
|
|
||||||
sizeof mad_snoop_priv *
|
|
||||||
qp_info->snoop_table_size);
|
|
||||||
kfree(qp_info->snoop_table);
|
|
||||||
}
|
|
||||||
qp_info->snoop_table = new_snoop_table;
|
qp_info->snoop_table = new_snoop_table;
|
||||||
qp_info->snoop_table_size++;
|
qp_info->snoop_table_size++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue