Re: [PATCH 39/44] mm: use min() instead of min_t()

From: David Hildenbrand (Red Hat)

Date: Thu Nov 20 2025 - 08:42:30 EST





Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
---
mm/gup.c | 4 ++--
mm/memblock.c | 2 +-
mm/memory.c | 2 +-
mm/percpu.c | 2 +-
mm/truncate.c | 3 +--
mm/vmscan.c | 2 +-
6 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/mm/gup.c b/mm/gup.c
index a8ba5112e4d0..55435b90dcc3 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -237,8 +237,8 @@ static inline struct folio *gup_folio_range_next(struct page *start,
unsigned int nr = 1;

if (folio_test_large(folio))
- nr = min_t(unsigned int, npages - i,
- folio_nr_pages(folio) - folio_page_idx(folio, next));
+ nr = min(npages - i,
+ folio_nr_pages(folio) - folio_page_idx(folio, next));

There's no cases where any of these would discard significant bits. But we
ultimately cast to unisnged int anyway (nr) so not sure this achieves anything.

The (implicit) cast to unsigned int is irrelevant - that happens after the min().
The issue is that 'npages' is 'unsigned long' so can (in theory) be larger than 4G.
Ok that would be a 16TB buffer, but someone must have decided that npages might
not fit in 32 bits otherwise they wouldn't have used 'unsigned long'.

See commit fa17bcd5f65e ("mm: make folio page count functions return unsigned") why that function used to return "long" instead of "unsigned int" and how we changed it to "unsigned long".

Until that function actually returns something that large might take a while, so no need to worry about that right now.



--
Cheers

David