_manager = NULL;
}
+static void
+ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update)
+{
+ unsigned i;
+
+ if (mem_count_update == 0)
+ goto put_pages;
+
+ for (i = 0; i < mem_count_update; ++i) {
+ if (!ttm->pages[i])
+ continue;
+
+ ttm_mem_global_free_page(ttm->glob->mem_glob, ttm->pages[i],
+ PAGE_SIZE);
+ }
+
+put_pages:
+ ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags,
+ ttm->caching_state);
+ ttm->state = tt_unpopulated;
+}
+
int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
{
struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;
ret = ttm_get_pages(ttm->pages, ttm->num_pages, ttm->page_flags,
ttm->caching_state);
if (unlikely(ret != 0)) {
- ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags,
- ttm->caching_state);
+ ttm_pool_unpopulate_helper(ttm, 0);
return ret;
}
ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
PAGE_SIZE, ctx);
if (unlikely(ret != 0)) {
- ttm_put_pages(ttm->pages, ttm->num_pages,
- ttm->page_flags, ttm->caching_state);
+ ttm_pool_unpopulate_helper(ttm, i);
return -ENOMEM;
}
}
void ttm_pool_unpopulate(struct ttm_tt *ttm)
{
- unsigned i;
-
- for (i = 0; i < ttm->num_pages; ++i) {
- if (!ttm->pages[i])
- continue;
-
- ttm_mem_global_free_page(ttm->glob->mem_glob, ttm->pages[i],
- PAGE_SIZE);
- }
- ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags,
- ttm->caching_state);
- ttm->state = tt_unpopulated;
+ ttm_pool_unpopulate_helper(ttm, ttm->num_pages);
}
EXPORT_SYMBOL(ttm_pool_unpopulate);