[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241122211144.4186080-2-bjohannesmeyer@gmail.com>
Date: Fri, 22 Nov 2024 22:11:42 +0100
From: Brian Johannesmeyer <bjohannesmeyer@...il.com>
To: Keith Busch <kbusch@...nel.org>,
Christoph Hellwig <hch@...radead.org>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-mm@...ck.org,
linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Cc: Brian Johannesmeyer <bjohannesmeyer@...il.com>,
Raphael Isemann <teemperor@...il.com>,
Cristiano Giuffrida <giuffrida@...vu.nl>,
Herbert Bos <h.j.bos@...nl>,
Greg KH <gregkh@...uxfoundation.org>
Subject: [PATCH v3 2/3] dmapool: Use pool_find_block() in pool_block_err()
In the previous patch, the `pool_find_block()` function was added to
translate a virtual address into the corresponding `struct dma_block`. The
existing `pool_find_page()` function performs a similar role by translating
a DMA address into the `struct dma_page` containing it.
To reduce redundant code and improve consistency, remove the
`pool_find_page()` function and update `pool_block_err()` to use
`pool_find_block()` instead. Doing so eliminates duplicate functionality
and consolidates the block lookup process.
Co-developed-by: Raphael Isemann <teemperor@...il.com>
Signed-off-by: Raphael Isemann <teemperor@...il.com>
Signed-off-by: Brian Johannesmeyer <bjohannesmeyer@...il.com>
---
mm/dmapool.c | 38 ++++++++++++--------------------------
1 file changed, 12 insertions(+), 26 deletions(-)
diff --git a/mm/dmapool.c b/mm/dmapool.c
index 3790ca4a631d..f2b96be25412 100644
--- a/mm/dmapool.c
+++ b/mm/dmapool.c
@@ -141,39 +141,25 @@ static void pool_check_block(struct dma_pool *pool, struct dma_block *block,
memset(block->vaddr, POOL_POISON_ALLOCATED, pool->size);
}
-static struct dma_page *pool_find_page(struct dma_pool *pool, dma_addr_t dma)
-{
- struct dma_page *page;
-
- list_for_each_entry(page, &pool->page_list, page_list) {
- if (dma < page->dma)
- continue;
- if ((dma - page->dma) < pool->allocation)
- return page;
- }
- return NULL;
-}
-
static bool pool_block_err(struct dma_pool *pool, void *vaddr, dma_addr_t dma)
{
- struct dma_block *block = pool->next_block;
- struct dma_page *page;
+ struct dma_block *block = pool_find_block(pool, vaddr);
- page = pool_find_page(pool, dma);
- if (!page) {
- dev_err(pool->dev, "%s %s, %p/%pad (bad dma)\n",
- __func__, pool->name, vaddr, &dma);
+ if (!block) {
+ dev_err(pool->dev, "%s %s, invalid block %p\n",
+ __func__, pool->name, vaddr);
return true;
}
- while (block) {
- if (block->vaddr != vaddr) {
- block = block->next_block;
- continue;
+ struct dma_block *iter = pool->next_block;
+
+ while (iter) {
+ if (iter == block) {
+ dev_err(pool->dev, "%s %s, dma %pad already free\n",
+ __func__, pool->name, &dma);
+ return true;
}
- dev_err(pool->dev, "%s %s, dma %pad already free\n",
- __func__, pool->name, &dma);
- return true;
+ iter = iter->next_block;
}
memset(vaddr, POOL_POISON_FREED, pool->size);
--
2.34.1
Powered by blists - more mailing lists