linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: make folio page count functions return unsigned
@ 2025-08-26 15:37 Aristeu Rozanski
  2025-08-26 19:00 ` Matthew Wilcox
  2025-08-27  9:13 ` David Hildenbrand
  0 siblings, 2 replies; 7+ messages in thread
From: Aristeu Rozanski @ 2025-08-26 15:37 UTC (permalink / raw)
  To: linux-mm
  Cc: David Hildenbrand, Andrew Morton, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter

As raised by Andrew [1], a folio/compound page never spans a negative number
of pages. Consequently, let's use "unsigned long" instead of "long"
consistently for folio_nr_pages(), folio_large_nr_pages() and compound_nr().

Using "unsigned long" as return value is fine, because even
"(long)-folio_nr_pages()" will keep on working as expected. Using "unsigned
int" instead would actually break these use cases.

This patch takes the first step changing these to return unsigned long (and
making drm_gem_get_pages() use the new types instead of replacing min()).

In the future, we might want to make more callers of these functions to
consistently use "unsigned long".

[1] https://lore.kernel.org/linux-mm/20250503182858.5a02729fcffd6d4723afcfc2@linux-foundation.org/

Link: https://lore.kernel.org/linux-mm/20250503182858.5a02729fcffd6d4723afcfc2@linux-foundation.org/
Signed-off-by: Aristeu Rozanski <aris@ruivo.org>
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: David Hildenbrand <david@redhat.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>

---
 drivers/gpu/drm/drm_gem.c |    4 ++--
 include/linux/mm.h        |    8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

--- linus-2.6.orig/drivers/gpu/drm/drm_gem.c	2025-08-11 14:52:45.878752324 -0400
+++ linus-2.6/drivers/gpu/drm/drm_gem.c	2025-08-19 00:31:01.495295839 -0400
@@ -620,7 +620,7 @@ struct page **drm_gem_get_pages(struct d
 	struct page **pages;
 	struct folio *folio;
 	struct folio_batch fbatch;
-	long i, j, npages;
+	unsigned long i, j, npages;
 
 	if (WARN_ON(!obj->filp))
 		return ERR_PTR(-EINVAL);
@@ -644,7 +644,7 @@ WARN_ON((obj->size & (PAGE_SIZE - 1)) !=
 
 	i = 0;
 	while (i < npages) {
-		long nr;
+		unsigned long nr;
 		folio = shmem_read_folio_gfp(mapping, i,
 				mapping_gfp_mask(mapping));
 		if (IS_ERR(folio))
--- linus-2.6.orig/include/linux/mm.h	2025-08-11 14:52:45.878752324 -0400
+++ linus-2.6/include/linux/mm.h	2025-08-11 14:53:00.396630632 -0400
@@ -951,12 +951,12 @@ return folio->_flags_1 & 0xff;
 }
 
 #ifdef NR_PAGES_IN_LARGE_FOLIO
-static inline long folio_large_nr_pages(const struct folio *folio)
+static inline unsigned long folio_large_nr_pages(const struct folio *folio)
 {
 	return folio->_nr_pages;
 }
 #else
-static inline long folio_large_nr_pages(const struct folio *folio)
+static inline unsigned long folio_large_nr_pages(const struct folio *folio)
 {
 	return 1L << folio_large_order(folio);
 }
@@ -1971,7 +1971,7 @@ static inline void set_page_links(struct
  *
  * Return: A positive power of two.
  */
-static inline long folio_nr_pages(const struct folio *folio)
+static inline unsigned long folio_nr_pages(const struct folio *folio)
 {
 	if (!folio_test_large(folio))
 		return 1;
@@ -1990,7 +1990,7 @@ static inline long folio_nr_pages(const
  * page.  compound_nr() can be called on a tail page, and is defined to
  * return 1 in that case.
  */
-static inline long compound_nr(struct page *page)
+static inline unsigned long compound_nr(struct page *page)
 {
 	struct folio *folio = (struct folio *)page;
 


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-08-27  9:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26 15:37 [PATCH] mm: make folio page count functions return unsigned Aristeu Rozanski
2025-08-26 19:00 ` Matthew Wilcox
2025-08-26 21:45   ` David Hildenbrand
2025-08-26 22:00     ` Aristeu Rozanski
2025-08-27  1:20       ` Matthew Wilcox
2025-08-27  9:14         ` David Hildenbrand
2025-08-27  9:13 ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).