Kill cma_pages_valid() which only used in cma_release(), also cleanup code duplication between cma pages valid checking and cma memrange finding. Reviewed-by: Jane Chu Reviewed-by: Zi Yan Reviewed-by: Muchun Song Acked-by: David Hildenbrand Signed-off-by: Kefeng Wang --- include/linux/cma.h | 1 - mm/cma.c | 48 +++++++++++---------------------------------- 2 files changed, 11 insertions(+), 38 deletions(-) diff --git a/include/linux/cma.h b/include/linux/cma.h index 62d9c1cf6326..e5745d2aec55 100644 --- a/include/linux/cma.h +++ b/include/linux/cma.h @@ -49,7 +49,6 @@ extern int cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, struct cma **res_cma); extern struct page *cma_alloc(struct cma *cma, unsigned long count, unsigned int align, bool no_warn); -extern bool cma_pages_valid(struct cma *cma, const struct page *pages, unsigned long count); extern bool cma_release(struct cma *cma, const struct page *pages, unsigned long count); extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data); diff --git a/mm/cma.c b/mm/cma.c index 813e6dc7b095..fe3a9eaac4e5 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -942,36 +942,6 @@ struct folio *cma_alloc_folio(struct cma *cma, int order, gfp_t gfp) return page ? page_folio(page) : NULL; } -bool cma_pages_valid(struct cma *cma, const struct page *pages, - unsigned long count) -{ - unsigned long pfn, end; - int r; - struct cma_memrange *cmr; - bool ret; - - if (!cma || !pages || count > cma->count) - return false; - - pfn = page_to_pfn(pages); - ret = false; - - for (r = 0; r < cma->nranges; r++) { - cmr = &cma->ranges[r]; - end = cmr->base_pfn + cmr->count; - if (pfn >= cmr->base_pfn && pfn < end) { - ret = pfn + count <= end; - break; - } - } - - if (!ret) - pr_debug("%s(page %p, count %lu)\n", - __func__, (void *)pages, count); - - return ret; -} - /** * cma_release() - release allocated pages * @cma: Contiguous memory region for which the allocation is performed. @@ -991,23 +961,27 @@ bool cma_release(struct cma *cma, const struct page *pages, pr_debug("%s(page %p, count %lu)\n", __func__, (void *)pages, count); - if (!cma_pages_valid(cma, pages, count)) + if (!cma || !pages || count > cma->count) return false; pfn = page_to_pfn(pages); - end_pfn = pfn + count; for (r = 0; r < cma->nranges; r++) { cmr = &cma->ranges[r]; - if (pfn >= cmr->base_pfn && - pfn < (cmr->base_pfn + cmr->count)) { - VM_BUG_ON(end_pfn > cmr->base_pfn + cmr->count); - break; + end_pfn = cmr->base_pfn + cmr->count; + if (pfn >= cmr->base_pfn && pfn < end_pfn) { + if (pfn + count <= end_pfn) + break; + + VM_WARN_ON_ONCE(1); } } - if (r == cma->nranges) + if (r == cma->nranges) { + pr_debug("%s(page %p, count %lu, no cma range matches the page range)\n", + __func__, (void *)pages, count); return false; + } free_contig_range(pfn, count); cma_clear_bitmap(cma, cmr, pfn, count); -- 2.27.0