Skip to content

Commit 5407df1

Browse files
keithbuschakpm00
authored andcommitted
dmapool: rearrange page alloc failure handling
Handle the error in a condition so the good path can be in the normal flow. Link: https://lkml.kernel.org/r/20230126215125.4069751-8-kbusch@meta.com Fixes: 2d55c16 ("dmapool: create/destroy cleanup") Signed-off-by: Keith Busch <kbusch@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: Matthew Wilcox <willy@infradead.org> Cc: Tony Battersby <tonyb@cybernetics.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent d93e08b commit 5407df1

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

mm/dmapool.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,19 @@ static struct dma_page *pool_alloc_page(struct dma_pool *pool, gfp_t mem_flags)
292292
page = kmalloc(sizeof(*page), mem_flags);
293293
if (!page)
294294
return NULL;
295+
295296
page->vaddr = dma_alloc_coherent(pool->dev, pool->allocation,
296297
&page->dma, mem_flags);
297-
if (page->vaddr) {
298-
pool_init_page(pool, page);
299-
pool_initialise_page(pool, page);
300-
page->in_use = 0;
301-
page->offset = 0;
302-
} else {
298+
if (!page->vaddr) {
303299
kfree(page);
304-
page = NULL;
300+
return NULL;
305301
}
302+
303+
pool_init_page(pool, page);
304+
pool_initialise_page(pool, page);
305+
page->in_use = 0;
306+
page->offset = 0;
307+
306308
return page;
307309
}
308310

0 commit comments

Comments
 (0)