Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: use proper type for cma_[alloc|release]

size_t in cma_alloc is confusing since it makes people think it's byte
count, not pages. Change it to unsigned long[1].

The unsigned int in cma_release is also not right so change it. Since we
have unsigned long in cma_release, free_contig_range should also respect
it.

[1] 67a2e213e7e9, mm: cma: fix incorrect type conversion for size during dma allocation

Link: https://lore.kernel.org/linux-mm/20210324043434.GP1719932@casper.infradead.org/
Link: https://lkml.kernel.org/r/20210331164018.710560-1-minchan@kernel.org
Signed-off-by: Minchan Kim <minchan@kernel.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: David Hildenbrand <david@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Minchan Kim and committed by
Linus Torvalds
78fa5150 3aab8ae7

+26 -25
+2 -2
include/linux/cma.h
··· 44 44 unsigned int order_per_bit, 45 45 const char *name, 46 46 struct cma **res_cma); 47 - extern struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, 47 + extern struct page *cma_alloc(struct cma *cma, unsigned long count, unsigned int align, 48 48 bool no_warn); 49 - extern bool cma_release(struct cma *cma, const struct page *pages, unsigned int count); 49 + extern bool cma_release(struct cma *cma, const struct page *pages, unsigned long count); 50 50 51 51 extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data); 52 52 #endif
+1 -1
include/linux/gfp.h
··· 657 657 extern struct page *alloc_contig_pages(unsigned long nr_pages, gfp_t gfp_mask, 658 658 int nid, nodemask_t *nodemask); 659 659 #endif 660 - void free_contig_range(unsigned long pfn, unsigned int nr_pages); 660 + void free_contig_range(unsigned long pfn, unsigned long nr_pages); 661 661 662 662 #ifdef CONFIG_CMA 663 663 /* CMA stuff */
+11 -11
include/trace/events/cma.h
··· 11 11 DECLARE_EVENT_CLASS(cma_alloc_class, 12 12 13 13 TP_PROTO(const char *name, unsigned long pfn, const struct page *page, 14 - unsigned int count, unsigned int align), 14 + unsigned long count, unsigned int align), 15 15 16 16 TP_ARGS(name, pfn, page, count, align), 17 17 ··· 19 19 __string(name, name) 20 20 __field(unsigned long, pfn) 21 21 __field(const struct page *, page) 22 - __field(unsigned int, count) 22 + __field(unsigned long, count) 23 23 __field(unsigned int, align) 24 24 ), 25 25 ··· 31 31 __entry->align = align; 32 32 ), 33 33 34 - TP_printk("name=%s pfn=%lx page=%p count=%u align=%u", 34 + TP_printk("name=%s pfn=%lx page=%p count=%lu align=%u", 35 35 __get_str(name), 36 36 __entry->pfn, 37 37 __entry->page, ··· 42 42 TRACE_EVENT(cma_release, 43 43 44 44 TP_PROTO(const char *name, unsigned long pfn, const struct page *page, 45 - unsigned int count), 45 + unsigned long count), 46 46 47 47 TP_ARGS(name, pfn, page, count), 48 48 ··· 50 50 __string(name, name) 51 51 __field(unsigned long, pfn) 52 52 __field(const struct page *, page) 53 - __field(unsigned int, count) 53 + __field(unsigned long, count) 54 54 ), 55 55 56 56 TP_fast_assign( ··· 60 60 __entry->count = count; 61 61 ), 62 62 63 - TP_printk("name=%s pfn=%lx page=%p count=%u", 63 + TP_printk("name=%s pfn=%lx page=%p count=%lu", 64 64 __get_str(name), 65 65 __entry->pfn, 66 66 __entry->page, ··· 69 69 70 70 TRACE_EVENT(cma_alloc_start, 71 71 72 - TP_PROTO(const char *name, unsigned int count, unsigned int align), 72 + TP_PROTO(const char *name, unsigned long count, unsigned int align), 73 73 74 74 TP_ARGS(name, count, align), 75 75 76 76 TP_STRUCT__entry( 77 77 __string(name, name) 78 - __field(unsigned int, count) 78 + __field(unsigned long, count) 79 79 __field(unsigned int, align) 80 80 ), 81 81 ··· 85 85 __entry->align = align; 86 86 ), 87 87 88 - TP_printk("name=%s count=%u align=%u", 88 + TP_printk("name=%s count=%lu align=%u", 89 89 __get_str(name), 90 90 __entry->count, 91 91 __entry->align) ··· 94 94 DEFINE_EVENT(cma_alloc_class, cma_alloc_finish, 95 95 96 96 TP_PROTO(const char *name, unsigned long pfn, const struct page *page, 97 - unsigned int count, unsigned int align), 97 + unsigned long count, unsigned int align), 98 98 99 99 TP_ARGS(name, pfn, page, count, align) 100 100 ); ··· 102 102 DEFINE_EVENT(cma_alloc_class, cma_alloc_busy_retry, 103 103 104 104 TP_PROTO(const char *name, unsigned long pfn, const struct page *page, 105 - unsigned int count, unsigned int align), 105 + unsigned long count, unsigned int align), 106 106 107 107 TP_ARGS(name, pfn, page, count, align) 108 108 );
+9 -8
mm/cma.c
··· 79 79 } 80 80 81 81 static void cma_clear_bitmap(struct cma *cma, unsigned long pfn, 82 - unsigned int count) 82 + unsigned long count) 83 83 { 84 84 unsigned long bitmap_no, bitmap_count; 85 85 unsigned long flags; ··· 423 423 * This function allocates part of contiguous memory on specific 424 424 * contiguous memory area. 425 425 */ 426 - struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, 427 - bool no_warn) 426 + struct page *cma_alloc(struct cma *cma, unsigned long count, 427 + unsigned int align, bool no_warn) 428 428 { 429 429 unsigned long mask, offset; 430 430 unsigned long pfn = -1; 431 431 unsigned long start = 0; 432 432 unsigned long bitmap_maxno, bitmap_no, bitmap_count; 433 - size_t i; 433 + unsigned long i; 434 434 struct page *page = NULL; 435 435 int ret = -ENOMEM; 436 436 437 437 if (!cma || !cma->count || !cma->bitmap) 438 438 goto out; 439 439 440 - pr_debug("%s(cma %p, count %zu, align %d)\n", __func__, (void *)cma, 440 + pr_debug("%s(cma %p, count %lu, align %d)\n", __func__, (void *)cma, 441 441 count, align); 442 442 443 443 if (!count) ··· 505 505 } 506 506 507 507 if (ret && !no_warn) { 508 - pr_err_ratelimited("%s: %s: alloc failed, req-size: %zu pages, ret: %d\n", 508 + pr_err_ratelimited("%s: %s: alloc failed, req-size: %lu pages, ret: %d\n", 509 509 __func__, cma->name, count, ret); 510 510 cma_debug_show_areas(cma); 511 511 } ··· 534 534 * It returns false when provided pages do not belong to contiguous area and 535 535 * true otherwise. 536 536 */ 537 - bool cma_release(struct cma *cma, const struct page *pages, unsigned int count) 537 + bool cma_release(struct cma *cma, const struct page *pages, 538 + unsigned long count) 538 539 { 539 540 unsigned long pfn; 540 541 541 542 if (!cma || !pages) 542 543 return false; 543 544 544 - pr_debug("%s(page %p, count %u)\n", __func__, (void *)pages, count); 545 + pr_debug("%s(page %p, count %lu)\n", __func__, (void *)pages, count); 545 546 546 547 pfn = page_to_pfn(pages); 547 548
+3 -3
mm/page_alloc.c
··· 8973 8973 } 8974 8974 #endif /* CONFIG_CONTIG_ALLOC */ 8975 8975 8976 - void free_contig_range(unsigned long pfn, unsigned int nr_pages) 8976 + void free_contig_range(unsigned long pfn, unsigned long nr_pages) 8977 8977 { 8978 - unsigned int count = 0; 8978 + unsigned long count = 0; 8979 8979 8980 8980 for (; nr_pages--; pfn++) { 8981 8981 struct page *page = pfn_to_page(pfn); ··· 8983 8983 count += page_count(page) != 1; 8984 8984 __free_page(page); 8985 8985 } 8986 - WARN(count != 0, "%d pages are still in use!\n", count); 8986 + WARN(count != 0, "%lu pages are still in use!\n", count); 8987 8987 } 8988 8988 EXPORT_SYMBOL(free_contig_range); 8989 8989