tbm_bufmgr_sprd: clean up tbm_sprd_bo_alloc() 51/97451/1
authorYoungJun Cho <yj44.cho@samsung.com>
Mon, 14 Nov 2016 07:11:58 +0000 (16:11 +0900)
committerYoungJun Cho <yj44.cho@samsung.com>
Mon, 14 Nov 2016 07:11:58 +0000 (16:11 +0900)
This patch cleans up tbm_sprd_bo_alloc().
- The privGem could be NULL if calloc() is failed.

Change-Id: I6052b6d5767191a6dc660a8aa7e5bd24b85a6d6d
Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
src/tbm_bufmgr_sprd.c

index 29eba0b..ecca133 100644 (file)
@@ -838,9 +838,9 @@ tbm_sprd_bo_alloc(tbm_bo bo, int size, int flags)
 {
        SPRD_RETURN_VAL_IF_FAIL(bo != NULL, 0);
 
-       tbm_bo_sprd bo_sprd;
        tbm_bufmgr_sprd bufmgr_sprd;
        unsigned int sprd_flags;
+       tbm_bo_sprd bo_sprd;
 
        bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo);
        SPRD_RETURN_VAL_IF_FAIL(bufmgr_sprd != NULL, 0);
@@ -858,11 +858,10 @@ tbm_sprd_bo_alloc(tbm_bo bo, int size, int flags)
        sprd_flags = SPRD_BO_CONTIG;
 #else
        sprd_flags = _get_sprd_flag_from_tbm(flags);
-       if ((flags & TBM_BO_SCANOUT) &&
-           size <= 4 * 1024) {
+       if ((flags & TBM_BO_SCANOUT) && (size <= 4 * 1024))
                sprd_flags |= SPRD_BO_NONCONTIG;
-       }
 #endif // USE_CONTIG_ONLY
+
        struct drm_sprd_gem_create arg = {0, };
        arg.size = (uint64_t)size;
        arg.flags = sprd_flags;
@@ -907,6 +906,14 @@ tbm_sprd_bo_alloc(tbm_bo bo, int size, int flags)
 
        /* add bo to hash */
        PrivGem *privGem = calloc(1, sizeof(PrivGem));
+       if (!privGem) {
+               TBM_SPRD_LOG("[libtbm-sprd:%d] "
+                             "error %s:%d Fail to calloc PrivGem\n",
+                             getpid(), __FUNCTION__, __LINE__);
+               free(bo_sprd);
+               return 0;
+       }
+
        privGem->ref_count = 1;
        privGem->bo_priv = bo_sprd;
        if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0) {