Commit 5b4262d7 authored by Tom St Denis's avatar Tom St Denis Committed by Alex Deucher

drm/ttm: Change ttm_tt page allocations to return errors

Explicitly return errors in ttm_tt_alloc_page_directory() and
ttm_dma_tt_alloc_page_directory() instead of relying on
further logic to detect errors.
Signed-off-by: default avatarTom St Denis <tom.stdenis@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 420457ac
...@@ -50,19 +50,25 @@ ...@@ -50,19 +50,25 @@
/** /**
* Allocates storage for pointers to the pages that back the ttm. * Allocates storage for pointers to the pages that back the ttm.
*/ */
static void ttm_tt_alloc_page_directory(struct ttm_tt *ttm) static int ttm_tt_alloc_page_directory(struct ttm_tt *ttm)
{ {
ttm->pages = kvmalloc_array(ttm->num_pages, sizeof(void*), ttm->pages = kvmalloc_array(ttm->num_pages, sizeof(void*),
GFP_KERNEL | __GFP_ZERO); GFP_KERNEL | __GFP_ZERO);
if (!ttm->pages)
return -ENOMEM;
return 0;
} }
static void ttm_dma_tt_alloc_page_directory(struct ttm_dma_tt *ttm) static int ttm_dma_tt_alloc_page_directory(struct ttm_dma_tt *ttm)
{ {
ttm->ttm.pages = kvmalloc_array(ttm->ttm.num_pages, ttm->ttm.pages = kvmalloc_array(ttm->ttm.num_pages,
sizeof(*ttm->ttm.pages) + sizeof(*ttm->ttm.pages) +
sizeof(*ttm->dma_address), sizeof(*ttm->dma_address),
GFP_KERNEL | __GFP_ZERO); GFP_KERNEL | __GFP_ZERO);
if (!ttm->ttm.pages)
return -ENOMEM;
ttm->dma_address = (void *) (ttm->ttm.pages + ttm->ttm.num_pages); ttm->dma_address = (void *) (ttm->ttm.pages + ttm->ttm.num_pages);
return 0;
} }
#ifdef CONFIG_X86 #ifdef CONFIG_X86
...@@ -197,8 +203,7 @@ int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev, ...@@ -197,8 +203,7 @@ int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev,
ttm->state = tt_unpopulated; ttm->state = tt_unpopulated;
ttm->swap_storage = NULL; ttm->swap_storage = NULL;
ttm_tt_alloc_page_directory(ttm); if (ttm_tt_alloc_page_directory(ttm)) {
if (!ttm->pages) {
ttm_tt_destroy(ttm); ttm_tt_destroy(ttm);
pr_err("Failed allocating page table\n"); pr_err("Failed allocating page table\n");
return -ENOMEM; return -ENOMEM;
...@@ -230,8 +235,7 @@ int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev, ...@@ -230,8 +235,7 @@ int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
ttm->swap_storage = NULL; ttm->swap_storage = NULL;
INIT_LIST_HEAD(&ttm_dma->pages_list); INIT_LIST_HEAD(&ttm_dma->pages_list);
ttm_dma_tt_alloc_page_directory(ttm_dma); if (ttm_dma_tt_alloc_page_directory(ttm_dma)) {
if (!ttm->pages) {
ttm_tt_destroy(ttm); ttm_tt_destroy(ttm);
pr_err("Failed allocating page table\n"); pr_err("Failed allocating page table\n");
return -ENOMEM; return -ENOMEM;
......
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