IB/hns: Optimize the logic of allocating memory using APIs

This patch modified the logic of allocating memory using APIs in
hns RoCE driver. We used kcalloc instead of kmalloc_array and
bitmap_zero. And When kcalloc failed, call vzalloc to alloc
memory.

Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
Signed-off-by: Ping Zhang <zhangping5@huawei.com>
Signed-off-by: Salil Mehta  <salil.mehta@huawei.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
This commit is contained in:
Wei Hu (Xavier) 2016-11-23 19:41:01 +00:00 коммит произвёл Doug Ledford
Родитель 8f3e9f3ea0
Коммит 8d497eb0f3
1 изменённых файлов: 9 добавлений и 7 удалений

Просмотреть файл

@ -137,11 +137,13 @@ static int hns_roce_buddy_init(struct hns_roce_buddy *buddy, int max_order)
for (i = 0; i <= buddy->max_order; ++i) { for (i = 0; i <= buddy->max_order; ++i) {
s = BITS_TO_LONGS(1 << (buddy->max_order - i)); s = BITS_TO_LONGS(1 << (buddy->max_order - i));
buddy->bits[i] = kmalloc_array(s, sizeof(long), GFP_KERNEL); buddy->bits[i] = kcalloc(s, sizeof(long), GFP_KERNEL |
__GFP_NOWARN);
if (!buddy->bits[i]) {
buddy->bits[i] = vzalloc(s * sizeof(long));
if (!buddy->bits[i]) if (!buddy->bits[i])
goto err_out_free; goto err_out_free;
}
bitmap_zero(buddy->bits[i], 1 << (buddy->max_order - i));
} }
set_bit(0, buddy->bits[buddy->max_order]); set_bit(0, buddy->bits[buddy->max_order]);
@ -151,7 +153,7 @@ static int hns_roce_buddy_init(struct hns_roce_buddy *buddy, int max_order)
err_out_free: err_out_free:
for (i = 0; i <= buddy->max_order; ++i) for (i = 0; i <= buddy->max_order; ++i)
kfree(buddy->bits[i]); kvfree(buddy->bits[i]);
err_out: err_out:
kfree(buddy->bits); kfree(buddy->bits);
@ -164,7 +166,7 @@ static void hns_roce_buddy_cleanup(struct hns_roce_buddy *buddy)
int i; int i;
for (i = 0; i <= buddy->max_order; ++i) for (i = 0; i <= buddy->max_order; ++i)
kfree(buddy->bits[i]); kvfree(buddy->bits[i]);
kfree(buddy->bits); kfree(buddy->bits);
kfree(buddy->num_free); kfree(buddy->num_free);