Skip to content

Commit

Permalink
dmapool: simplify freeing
Browse files Browse the repository at this point in the history
The actions for busy and not busy are mostly the same, so combine these
and remove the unnecessary function.  Also, the pool is about to be freed
so there's no need to poison the page data since we only check for poison
on alloc, which can't be done on a freed pool.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: 2d55c16 ("dmapool: create/destroy cleanup")
Signed-off-by: Keith Busch <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Tony Battersby <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
keithbusch authored and akpm00 committed May 6, 2023
1 parent f0bccea commit cc66995
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions mm/dmapool.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,6 @@ static inline bool is_page_busy(struct dma_page *page)
return page->in_use != 0;
}

static void pool_free_page(struct dma_pool *pool, struct dma_page *page)
{
dma_addr_t dma = page->dma;

pool_init_page(pool, page);
dma_free_coherent(pool->dev, pool->allocation, page->vaddr, dma);
list_del(&page->page_list);
kfree(page);
}

/**
* dma_pool_destroy - destroys a pool of dma memory blocks.
* @pool: dma pool that will be destroyed
Expand Down Expand Up @@ -349,14 +339,14 @@ void dma_pool_destroy(struct dma_pool *pool)
mutex_unlock(&pools_reg_lock);

list_for_each_entry_safe(page, tmp, &pool->page_list, page_list) {
if (is_page_busy(page)) {
if (!is_page_busy(page))
dma_free_coherent(pool->dev, pool->allocation,
page->vaddr, page->dma);
else
dev_err(pool->dev, "%s %s, %p busy\n", __func__,
pool->name, page->vaddr);
/* leak the still-in-use consistent memory */
list_del(&page->page_list);
kfree(page);
} else
pool_free_page(pool, page);
list_del(&page->page_list);
kfree(page);
}

kfree(pool);
Expand Down

0 comments on commit cc66995

Please sign in to comment.