drm/amdgpu: fix gtt available page num accounting
authorFlora Cui <Flora.Cui@amd.com>
Fri, 2 Dec 2016 08:51:20 +0000 (16:51 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 6 Dec 2016 23:08:34 +0000 (18:08 -0500)
Signed-off-by: Flora Cui <Flora.Cui@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c

index 3c634f02a3d5b259bbc4f94a8cdf054e8e35457a..00f46b0e076ddd9c8ce9d7a98668c2f02b31c1b6 100644 (file)
@@ -164,8 +164,10 @@ static int amdgpu_gtt_mgr_new(struct ttm_mem_type_manager *man,
        spin_unlock(&mgr->lock);
 
        node = kzalloc(sizeof(*node), GFP_KERNEL);
-       if (!node)
-               return -ENOMEM;
+       if (!node) {
+               r = -ENOMEM;
+               goto err_out;
+       }
 
        node->start = AMDGPU_BO_INVALID_OFFSET;
        node->size = mem->num_pages;
@@ -176,12 +178,20 @@ static int amdgpu_gtt_mgr_new(struct ttm_mem_type_manager *man,
                if (unlikely(r)) {
                        kfree(node);
                        mem->mm_node = NULL;
+                       r = 0;
+                       goto err_out;
                }
        } else {
                mem->start = node->start;
        }
 
        return 0;
+err_out:
+       spin_lock(&mgr->lock);
+       mgr->available += mem->num_pages;
+       spin_unlock(&mgr->lock);
+
+       return r;
 }
 
 /**