IB/rdmavt: Check lkey_table_size value before use

The lkey_table_size driver specific parameter value is used before its
value is sanity checked and restricted to RVT_MAX_LKEY_TABLE_BITS.

This causes a vmalloc allocation failure for large values. Fix this
by moving the value check before the first usage of the value.

Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Jubin John <jubin.john@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
This commit is contained in:
Jubin John 2016-02-26 13:33:08 -08:00 committed by Doug Ledford
parent 582e05c3de
commit ade302405f
1 changed files with 1 additions and 2 deletions

View File

@ -76,8 +76,6 @@ int rvt_driver_mr_init(struct rvt_dev_info *rdi)
spin_lock_init(&rdi->lkey_table.lock); spin_lock_init(&rdi->lkey_table.lock);
rdi->lkey_table.max = 1 << lkey_table_size;
/* ensure generation is at least 4 bits */ /* ensure generation is at least 4 bits */
if (lkey_table_size > RVT_MAX_LKEY_TABLE_BITS) { if (lkey_table_size > RVT_MAX_LKEY_TABLE_BITS) {
rvt_pr_warn(rdi, "lkey bits %u too large, reduced to %u\n", rvt_pr_warn(rdi, "lkey bits %u too large, reduced to %u\n",
@ -85,6 +83,7 @@ int rvt_driver_mr_init(struct rvt_dev_info *rdi)
rdi->dparms.lkey_table_size = RVT_MAX_LKEY_TABLE_BITS; rdi->dparms.lkey_table_size = RVT_MAX_LKEY_TABLE_BITS;
lkey_table_size = rdi->dparms.lkey_table_size; lkey_table_size = rdi->dparms.lkey_table_size;
} }
rdi->lkey_table.max = 1 << lkey_table_size;
lk_tab_size = rdi->lkey_table.max * sizeof(*rdi->lkey_table.table); lk_tab_size = rdi->lkey_table.max * sizeof(*rdi->lkey_table.table);
rdi->lkey_table.table = (struct rvt_mregion __rcu **) rdi->lkey_table.table = (struct rvt_mregion __rcu **)
vmalloc_node(lk_tab_size, rdi->dparms.node); vmalloc_node(lk_tab_size, rdi->dparms.node);