@@ -582,24 +582,30 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
582
582
{
583
583
static const struct ttm_place sys_mem = { .mem_type = TTM_PL_SYSTEM };
584
584
struct ttm_buffer_object * ghost ;
585
+ struct ttm_resource * sys_res ;
585
586
struct ttm_tt * ttm ;
586
587
int ret ;
587
588
589
+ ret = ttm_resource_alloc (bo , & sys_mem , & sys_res );
590
+ if (ret )
591
+ return ret ;
592
+
588
593
/* If already idle, no need for ghost object dance. */
589
594
ret = ttm_bo_wait (bo , false, true);
590
595
if (ret != - EBUSY ) {
591
596
if (!bo -> ttm ) {
592
597
/* See comment below about clearing. */
593
598
ret = ttm_tt_create (bo , true);
594
599
if (ret )
595
- return ret ;
600
+ goto error_free_sys_mem ;
596
601
} else {
597
602
ttm_tt_unpopulate (bo -> bdev , bo -> ttm );
598
603
if (bo -> type == ttm_bo_type_device )
599
604
ttm_tt_mark_for_clear (bo -> ttm );
600
605
}
601
606
ttm_resource_free (bo , & bo -> resource );
602
- return ttm_resource_alloc (bo , & sys_mem , & bo -> resource );
607
+ ttm_bo_assign_mem (bo , sys_res );
608
+ return 0 ;
603
609
}
604
610
605
611
/*
@@ -615,13 +621,11 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
615
621
ret = ttm_tt_create (bo , true);
616
622
swap (bo -> ttm , ttm );
617
623
if (ret )
618
- return ret ;
624
+ goto error_free_sys_mem ;
619
625
620
626
ret = ttm_buffer_object_transfer (bo , & ghost );
621
- if (ret ) {
622
- ttm_tt_destroy (bo -> bdev , ttm );
623
- return ret ;
624
- }
627
+ if (ret )
628
+ goto error_destroy_tt ;
625
629
626
630
ret = dma_resv_copy_fences (& ghost -> base ._resv , bo -> base .resv );
627
631
/* Last resort, wait for the BO to be idle when we are OOM */
@@ -631,6 +635,14 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
631
635
dma_resv_unlock (& ghost -> base ._resv );
632
636
ttm_bo_put (ghost );
633
637
bo -> ttm = ttm ;
638
+ bo -> resource = NULL ;
639
+ ttm_bo_assign_mem (bo , sys_res );
640
+ return 0 ;
641
+
642
+ error_destroy_tt :
643
+ ttm_tt_destroy (bo -> bdev , ttm );
634
644
635
- return ttm_resource_alloc (bo , & sys_mem , & bo -> resource );
645
+ error_free_sys_mem :
646
+ ttm_resource_free (bo , & sys_res );
647
+ return ret ;
636
648
}
0 commit comments