[PATCH RFC 15/35] fs: hugetlbfs: remove nth_page() usage within folio in adjust_range_hwpoison()

David Hildenbrand
2025-08-21T21:33:41Z

The nth_page() is not really required anymore, so let's remove it.
While at it, cleanup and simplify the code a bit.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
fs/hugetlbfs/inode.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 34d496a2b7de6..dc981509a7717 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -198,31 +198,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
static size_t adjust_range_hwpoison(struct folio *folio, size_t offset,
size_t bytes)
{
- struct page *page;
- size_t n = 0;
- size_t res = 0;
+ struct page *page = folio_page(folio, offset / PAGE_SIZE);
+ size_t n, safe_bytes;

- /* First page to start the loop. */
- page = folio_page(folio, offset / PAGE_SIZE);
offset %= PAGE_SIZE;
- while (1) {
+ for (safe_bytes = 0; safe_bytes < bytes; safe_bytes += n) {
+
if (is_raw_hwpoison_page_in_hugepage(page))
break;

/* Safe to read n bytes without touching HWPOISON subpage. */
- n = min(bytes, (size_t)PAGE_SIZE - offset);
- res += n;
- bytes -= n;
- if (!bytes || !n)
- break;
- offset += n;
- if (offset == PAGE_SIZE) {
- page = nth_page(page, 1);
- offset = 0;
- }
+ n = min(bytes - safe_bytes, (size_t)PAGE_SIZE - offset);
+ offset = 0;
+ page++;
}

- return res;
+ return safe_bytes;
}

/*
--
2.50.1