[PATCH 10/11] dmapool: don't memset on free twice
From: Keith Busch
Date: Mon Dec 05 2022 - 10:07:26 EST
From: Keith Busch <kbusch@xxxxxxxxxx>
If debug is enabled, dmapool will poison the range, so no need to clear
it to 0 immediately before writing over it.
Signed-off-by: Keith Busch <kbusch@xxxxxxxxxx>
---
mm/dmapool.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/mm/dmapool.c b/mm/dmapool.c
index 44622f2bf4641..f5b79c3268856 100644
--- a/mm/dmapool.c
+++ b/mm/dmapool.c
@@ -372,10 +372,10 @@ static struct dma_page *pool_find_page(struct dma_pool *pool, dma_addr_t dma)
return NULL;
}
+#ifdef DMAPOOL_DEBUG
static inline bool pool_page_err(struct dma_pool *pool, struct dma_page *page,
void *vaddr)
{
-#ifdef DMAPOOL_DEBUG
unsigned int chain = page->offset;
if ((dma - page->dma) != offset) {
@@ -394,9 +394,17 @@ static inline bool pool_page_err(struct dma_pool *pool, struct dma_page *page,
return true;
}
memset(vaddr, POOL_POISON_FREED, pool->size);
-#endif
return false;
}
+#else
+static inline bool pool_page_err(struct dma_pool *pool, struct dma_page *page,
+ void *vaddr)
+{
+ if (want_init_on_free())
+ memset(vaddr, 0, pool->size);
+ return false;
+}
+#endif
/**
* dma_pool_free - put block back into dma pool
@@ -423,8 +431,6 @@ void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t dma)
}
offset = vaddr - page->vaddr;
- if (want_init_on_free())
- memset(vaddr, 0, pool->size);
if (pool_page_err(pool, page, vaddr)) {
spin_unlock_irqrestore(&pool->lock, flags);
return;
--
2.30.2