Browse Source

drm/amdgpu: fix gtt available page num accounting

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>
Flora Cui 8 years ago
parent
commit
47e50d5c0d
1 changed files with 12 additions and 2 deletions
  1. 12 2
      drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c

+ 12 - 2
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c

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