Commit d234eee1 authored by Maarten Maathuis's avatar Maarten Maathuis Committed by Greg Kroah-Hartman

drm/ttm: handle OOM in ttm_tt_swapout

commit 290e5505 upstream.

- Without this change I get a general protection fault.
- Also use PTR_ERR where applicable.
Signed-off-by: default avatarMaarten Maathuis <madman2003@gmail.com>
Reviewed-by: default avatarDave Airlie <airlied@redhat.com>
Acked-by: default avatarThomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 605fa278
...@@ -466,7 +466,7 @@ static int ttm_tt_swapin(struct ttm_tt *ttm) ...@@ -466,7 +466,7 @@ static int ttm_tt_swapin(struct ttm_tt *ttm)
void *from_virtual; void *from_virtual;
void *to_virtual; void *to_virtual;
int i; int i;
int ret; int ret = -ENOMEM;
if (ttm->page_flags & TTM_PAGE_FLAG_USER) { if (ttm->page_flags & TTM_PAGE_FLAG_USER) {
ret = ttm_tt_set_user(ttm, ttm->tsk, ttm->start, ret = ttm_tt_set_user(ttm, ttm->tsk, ttm->start,
...@@ -485,8 +485,10 @@ static int ttm_tt_swapin(struct ttm_tt *ttm) ...@@ -485,8 +485,10 @@ static int ttm_tt_swapin(struct ttm_tt *ttm)
for (i = 0; i < ttm->num_pages; ++i) { for (i = 0; i < ttm->num_pages; ++i) {
from_page = read_mapping_page(swap_space, i, NULL); from_page = read_mapping_page(swap_space, i, NULL);
if (IS_ERR(from_page)) if (IS_ERR(from_page)) {
ret = PTR_ERR(from_page);
goto out_err; goto out_err;
}
to_page = __ttm_tt_get_page(ttm, i); to_page = __ttm_tt_get_page(ttm, i);
if (unlikely(to_page == NULL)) if (unlikely(to_page == NULL))
goto out_err; goto out_err;
...@@ -509,7 +511,7 @@ static int ttm_tt_swapin(struct ttm_tt *ttm) ...@@ -509,7 +511,7 @@ static int ttm_tt_swapin(struct ttm_tt *ttm)
return 0; return 0;
out_err: out_err:
ttm_tt_free_alloced_pages(ttm); ttm_tt_free_alloced_pages(ttm);
return -ENOMEM; return ret;
} }
int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage) int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage)
...@@ -521,6 +523,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage) ...@@ -521,6 +523,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage)
void *from_virtual; void *from_virtual;
void *to_virtual; void *to_virtual;
int i; int i;
int ret = -ENOMEM;
BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated); BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated);
BUG_ON(ttm->caching_state != tt_cached); BUG_ON(ttm->caching_state != tt_cached);
...@@ -543,7 +546,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage) ...@@ -543,7 +546,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage)
0); 0);
if (unlikely(IS_ERR(swap_storage))) { if (unlikely(IS_ERR(swap_storage))) {
printk(KERN_ERR "Failed allocating swap storage.\n"); printk(KERN_ERR "Failed allocating swap storage.\n");
return -ENOMEM; return PTR_ERR(swap_storage);
} }
} else } else
swap_storage = persistant_swap_storage; swap_storage = persistant_swap_storage;
...@@ -555,9 +558,10 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage) ...@@ -555,9 +558,10 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage)
if (unlikely(from_page == NULL)) if (unlikely(from_page == NULL))
continue; continue;
to_page = read_mapping_page(swap_space, i, NULL); to_page = read_mapping_page(swap_space, i, NULL);
if (unlikely(to_page == NULL)) if (unlikely(IS_ERR(to_page))) {
ret = PTR_ERR(to_page);
goto out_err; goto out_err;
}
preempt_disable(); preempt_disable();
from_virtual = kmap_atomic(from_page, KM_USER0); from_virtual = kmap_atomic(from_page, KM_USER0);
to_virtual = kmap_atomic(to_page, KM_USER1); to_virtual = kmap_atomic(to_page, KM_USER1);
...@@ -581,5 +585,5 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage) ...@@ -581,5 +585,5 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage)
if (!persistant_swap_storage) if (!persistant_swap_storage)
fput(swap_storage); fput(swap_storage);
return -ENOMEM; return ret;
} }
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