diff options
author | Maarten Maathuis <madman2003@gmail.com> | 2010-02-19 21:22:21 -0500 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2010-02-24 22:33:04 -0500 |
commit | 290e55056ec3d25c72088628245d8cae037b30db (patch) | |
tree | 5496a6ab798602063e5d27d5d31caa102f44ded2 /drivers | |
parent | 6a8a2d702b33c6ed5c789f21b4e89fdf221f01ca (diff) |
drm/ttm: handle OOM in ttm_tt_swapout
- Without this change I get a general protection fault.
- Also use PTR_ERR where applicable.
Signed-off-by: Maarten Maathuis <madman2003@gmail.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Acked-by: Thomas Hellstrom <thellstrom@vmware.com>
Cc: stable@kernel.org
Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpu/drm/ttm/ttm_tt.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c index e2123af7775a..160c2745f8d8 100644 --- a/drivers/gpu/drm/ttm/ttm_tt.c +++ b/drivers/gpu/drm/ttm/ttm_tt.c | |||
@@ -476,7 +476,7 @@ static int ttm_tt_swapin(struct ttm_tt *ttm) | |||
476 | void *from_virtual; | 476 | void *from_virtual; |
477 | void *to_virtual; | 477 | void *to_virtual; |
478 | int i; | 478 | int i; |
479 | int ret; | 479 | int ret = -ENOMEM; |
480 | 480 | ||
481 | if (ttm->page_flags & TTM_PAGE_FLAG_USER) { | 481 | if (ttm->page_flags & TTM_PAGE_FLAG_USER) { |
482 | ret = ttm_tt_set_user(ttm, ttm->tsk, ttm->start, | 482 | ret = ttm_tt_set_user(ttm, ttm->tsk, ttm->start, |
@@ -495,8 +495,10 @@ static int ttm_tt_swapin(struct ttm_tt *ttm) | |||
495 | 495 | ||
496 | for (i = 0; i < ttm->num_pages; ++i) { | 496 | for (i = 0; i < ttm->num_pages; ++i) { |
497 | from_page = read_mapping_page(swap_space, i, NULL); | 497 | from_page = read_mapping_page(swap_space, i, NULL); |
498 | if (IS_ERR(from_page)) | 498 | if (IS_ERR(from_page)) { |
499 | ret = PTR_ERR(from_page); | ||
499 | goto out_err; | 500 | goto out_err; |
501 | } | ||
500 | to_page = __ttm_tt_get_page(ttm, i); | 502 | to_page = __ttm_tt_get_page(ttm, i); |
501 | if (unlikely(to_page == NULL)) | 503 | if (unlikely(to_page == NULL)) |
502 | goto out_err; | 504 | goto out_err; |
@@ -519,7 +521,7 @@ static int ttm_tt_swapin(struct ttm_tt *ttm) | |||
519 | return 0; | 521 | return 0; |
520 | out_err: | 522 | out_err: |
521 | ttm_tt_free_alloced_pages(ttm); | 523 | ttm_tt_free_alloced_pages(ttm); |
522 | return -ENOMEM; | 524 | return ret; |
523 | } | 525 | } |
524 | 526 | ||
525 | int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage) | 527 | int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage) |
@@ -531,6 +533,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage) | |||
531 | void *from_virtual; | 533 | void *from_virtual; |
532 | void *to_virtual; | 534 | void *to_virtual; |
533 | int i; | 535 | int i; |
536 | int ret = -ENOMEM; | ||
534 | 537 | ||
535 | BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated); | 538 | BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated); |
536 | BUG_ON(ttm->caching_state != tt_cached); | 539 | BUG_ON(ttm->caching_state != tt_cached); |
@@ -553,7 +556,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage) | |||
553 | 0); | 556 | 0); |
554 | if (unlikely(IS_ERR(swap_storage))) { | 557 | if (unlikely(IS_ERR(swap_storage))) { |
555 | printk(KERN_ERR "Failed allocating swap storage.\n"); | 558 | printk(KERN_ERR "Failed allocating swap storage.\n"); |
556 | return -ENOMEM; | 559 | return PTR_ERR(swap_storage); |
557 | } | 560 | } |
558 | } else | 561 | } else |
559 | swap_storage = persistant_swap_storage; | 562 | swap_storage = persistant_swap_storage; |
@@ -565,9 +568,10 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistant_swap_storage) | |||
565 | if (unlikely(from_page == NULL)) | 568 | if (unlikely(from_page == NULL)) |
566 | continue; | 569 | continue; |
567 | to_page = read_mapping_page(swap_space, i, NULL); | 570 | to_page = read_mapping_page(swap_space, i, NULL); |
568 | if (unlikely(to_page == NULL)) | 571 | if (unlikely(IS_ERR(to_page))) { |
572 | ret = PTR_ERR(to_page); | ||
569 | goto out_err; | 573 | goto out_err; |
570 | 574 | } | |
571 | preempt_disable(); | 575 | preempt_disable(); |
572 | from_virtual = kmap_atomic(from_page, KM_USER0); | 576 | from_virtual = kmap_atomic(from_page, KM_USER0); |
573 | to_virtual = kmap_atomic(to_page, KM_USER1); | 577 | to_virtual = kmap_atomic(to_page, KM_USER1); |
@@ -591,5 +595,5 @@ out_err: | |||
591 | if (!persistant_swap_storage) | 595 | if (!persistant_swap_storage) |
592 | fput(swap_storage); | 596 | fput(swap_storage); |
593 | 597 | ||
594 | return -ENOMEM; | 598 | return ret; |
595 | } | 599 | } |