gpu: nvgpu: check sema pool alloc failure properly

nvgpu_semaphore_pool_alloc() returns an ERR_PTR instead of NULL which
the caller checks on failure. Common code should not use ERR_PTRs
though, so modify nvgpu_semaphore_pool_alloc() to return error code
separately and fix nvgpu_init_sema_pool() to consider this.

Jira NVGPU-513

Change-Id: I435c0d2794d226774ed4c6b3bcbdde1e741854d8
Signed-off-by: Konsta Holtta <kholtta@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1673458
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Konsta Holtta
2018-03-22 18:25:05 +02:00
committed by mobile promotions
parent b5b4353ca6
commit 90925a739a
3 changed files with 15 additions and 16 deletions

View File

@@ -146,29 +146,27 @@ static int __semaphore_bitmap_alloc(unsigned long *bitmap, unsigned long len)
/*
* Allocate a pool from the sea.
*/
struct nvgpu_semaphore_pool *nvgpu_semaphore_pool_alloc(
struct nvgpu_semaphore_sea *sea)
int nvgpu_semaphore_pool_alloc(struct nvgpu_semaphore_sea *sea,
struct nvgpu_semaphore_pool **pool)
{
struct nvgpu_semaphore_pool *p;
unsigned long page_idx;
int ret, err = 0;
int ret;
p = nvgpu_kzalloc(sea->gk20a, sizeof(*p));
if (!p)
return ERR_PTR(-ENOMEM);
return -ENOMEM;
__lock_sema_sea(sea);
err = nvgpu_mutex_init(&p->pool_lock);
if (err)
ret = nvgpu_mutex_init(&p->pool_lock);
if (ret)
goto fail;
ret = __semaphore_bitmap_alloc(sea->pools_alloced,
SEMAPHORE_POOL_COUNT);
if (ret < 0) {
err = ret;
if (ret < 0)
goto fail_alloc;
}
page_idx = (unsigned long)ret;
@@ -184,7 +182,8 @@ struct nvgpu_semaphore_pool *nvgpu_semaphore_pool_alloc(
gpu_sema_dbg(sea->gk20a,
"Allocated semaphore pool: page-idx=%d", p->page_idx);
return p;
*pool = p;
return 0;
fail_alloc:
nvgpu_mutex_destroy(&p->pool_lock);
@@ -192,7 +191,7 @@ fail:
__unlock_sema_sea(sea);
nvgpu_kfree(sea->gk20a, p);
gpu_sema_dbg(sea->gk20a, "Failed to allocate semaphore pool!");
return ERR_PTR(err);
return ret;
}
/*