Commit 0839152f authored by Ofir Bitton's avatar Ofir Bitton Committed by Oded Gabbay

habanalabs: check correct vmalloc return code

vmalloc can return different return code than NULL and a valid
pointer. We must validate it in order to dereference a non valid
pointer.
Signed-off-by: default avatarOfir Bitton <obitton@habana.ai>
Signed-off-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
parent bce382a8
...@@ -66,6 +66,11 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args, ...@@ -66,6 +66,11 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args,
num_pgs = (args->alloc.mem_size + (page_size - 1)) >> page_shift; num_pgs = (args->alloc.mem_size + (page_size - 1)) >> page_shift;
total_size = num_pgs << page_shift; total_size = num_pgs << page_shift;
if (!total_size) {
dev_err(hdev->dev, "Cannot allocate 0 bytes\n");
return -EINVAL;
}
contiguous = args->flags & HL_MEM_CONTIGUOUS; contiguous = args->flags & HL_MEM_CONTIGUOUS;
if (contiguous) { if (contiguous) {
...@@ -93,7 +98,7 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args, ...@@ -93,7 +98,7 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args,
phys_pg_pack->contiguous = contiguous; phys_pg_pack->contiguous = contiguous;
phys_pg_pack->pages = kvmalloc_array(num_pgs, sizeof(u64), GFP_KERNEL); phys_pg_pack->pages = kvmalloc_array(num_pgs, sizeof(u64), GFP_KERNEL);
if (!phys_pg_pack->pages) { if (ZERO_OR_NULL_PTR(phys_pg_pack->pages)) {
rc = -ENOMEM; rc = -ENOMEM;
goto pages_arr_err; goto pages_arr_err;
} }
...@@ -683,7 +688,7 @@ static int init_phys_pg_pack_from_userptr(struct hl_ctx *ctx, ...@@ -683,7 +688,7 @@ static int init_phys_pg_pack_from_userptr(struct hl_ctx *ctx,
phys_pg_pack->pages = kvmalloc_array(total_npages, sizeof(u64), phys_pg_pack->pages = kvmalloc_array(total_npages, sizeof(u64),
GFP_KERNEL); GFP_KERNEL);
if (!phys_pg_pack->pages) { if (ZERO_OR_NULL_PTR(phys_pg_pack->pages)) {
rc = -ENOMEM; rc = -ENOMEM;
goto page_pack_arr_mem_err; goto page_pack_arr_mem_err;
} }
......
...@@ -450,7 +450,7 @@ int hl_mmu_init(struct hl_device *hdev) ...@@ -450,7 +450,7 @@ int hl_mmu_init(struct hl_device *hdev)
hdev->mmu_shadow_hop0 = kvmalloc_array(prop->max_asid, hdev->mmu_shadow_hop0 = kvmalloc_array(prop->max_asid,
prop->mmu_hop_table_size, prop->mmu_hop_table_size,
GFP_KERNEL | __GFP_ZERO); GFP_KERNEL | __GFP_ZERO);
if (!hdev->mmu_shadow_hop0) { if (ZERO_OR_NULL_PTR(hdev->mmu_shadow_hop0)) {
rc = -ENOMEM; rc = -ENOMEM;
goto err_pool_add; goto err_pool_add;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment