[PATCH] mm/memfd_luo: use real folio index in retrieve error logs

From: Giorgi Tchankvetadze

Date: Thu Aug 06 2026 - 06:07:58 EST


From: Giorgi Tchankvetadze <giorgi@xxxxxxxxxxxxxxxxx>

memfd_luo_retrieve_folios() logs "folio index %ld" on its error paths
but passes the loop counter 'i' instead of the folio's actual index
held in the local 'index' variable (pfolio->index).

Pass 'index' to the three pr_err() calls so the logged index matches
the folio that actually failed. Since the saved index is a u64, use %llu with an
unsigned long long cast when printing it.

Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd")
Signed-off-by: Giorgi Tchankvetadze <giorgi@xxxxxxxxxxxxxxxxx>
---
mm/memfd_luo.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c
index 59de210bee5f..652dd21e6ef0 100644
--- a/mm/memfd_luo.c
+++ b/mm/memfd_luo.c
@@ -451,16 +451,16 @@ static int memfd_luo_retrieve_folios(struct file *file,

err = mem_cgroup_charge(folio, NULL, mapping_gfp_mask(mapping));
if (err) {
- pr_err("shmem: failed to charge folio index %ld: %d\n",
- i, err);
+ pr_err("shmem: failed to charge folio index %llu: %d\n",
+ (unsigned long long)index, err);
goto unlock_folio;
}

err = shmem_add_to_page_cache(folio, mapping, index, NULL,
mapping_gfp_mask(mapping));
if (err) {
- pr_err("shmem: failed to add to page cache folio index %ld: %d\n",
- i, err);
+ pr_err("shmem: failed to add to page cache folio index %llu: %d\n",
+ (unsigned long long)index, err);
goto unlock_folio;
}

@@ -472,8 +472,8 @@ static int memfd_luo_retrieve_folios(struct file *file,
npages = folio_nr_pages(folio);
err = shmem_inode_acct_blocks(inode, npages);
if (err) {
- pr_err("shmem: failed to account folio index %ld(%ld pages): %d\n",
- i, npages, err);
+ pr_err("shmem: failed to account folio index %llu(%ld pages): %d\n",
+ (unsigned long long)index, npages, err);
goto remove_from_cache;
}

--
2.52.0