On 9/18/26 4:52 PM, Sarthak Sharma wrote:
> Change read_file(), write_file(), read_num(), write_num() and
> write_num_ignore_einval() in vm_util.c to report failures to callers
> instead of exiting from the helper.
> 
> Make read_file() return a negative errno on failure and 0 on success, so
> callers can distinguish a successful read from an I/O error. Also make
> read_num() reject negative and malformed values.
> 
> Keep write_num_ignore_einval() silent for -EINVAL while returning other
> errors to its caller.
> 
> Update callers to print diagnostics and fail wherever required. Modify
> a comment which implies write_num() uses ksft_exit_fail_msg(). Also add
> a helper print_file_access_error() in hugepage_settings.c to print
> TAP-compatible errors without a kselftest dependency. This prepares the
> helpers to be moved to tools/lib/mm without a kselftest dependency.
> 
> Acked-by: Mike Rapoport (Microsoft) <[email protected]>
> Acked-by: David Hildenbrand (Arm) <[email protected]>
> Tested-by: Muhammad Usama Anjum <[email protected]>
> Signed-off-by: Sarthak Sharma <[email protected]>
> ---
Hi Andrew!

This fixes an MM selftest build failure in patch 1/6: read_num() changed
its interface, but hugetlb_nr_resv_pages() was missed during the caller
conversion. I'm sorry for missing this.

Can you please apply this fixlet after this patch and before the next
one? Sorry for the inconvenience again.


>From f7cfae95a1d0554ea03df320d91641979a9ac473 Mon Sep 17 00:00:00 2001
From: Sarthak Sharma <[email protected]>
Date: Fri, 18 Sep 2026 17:40:50 +0530
Subject: [PATCH] fixup! selftests/mm: make file helpers return errors

Convert hugetlb_nr_resv_pages(), which was missed when read_num()
changed to return an error and store the parsed value through an output
pointer.

Signed-off-by: Sarthak Sharma <[email protected]>
---
 tools/testing/selftests/mm/hugepage_settings.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/mm/hugepage_settings.c
b/tools/testing/selftests/mm/hugepage_settings.c
index 9a63420d0744..6f3abd357385 100644
--- a/tools/testing/selftests/mm/hugepage_settings.c
+++ b/tools/testing/selftests/mm/hugepage_settings.c
@@ -515,10 +515,18 @@ unsigned long hugetlb_free_pages(unsigned long size)
 unsigned long hugetlb_nr_resv_pages(unsigned long size)
 {
        char path[PATH_MAX];
+       unsigned long nr;
+       int ret;

        hugetlb_sysfs_path(path, sizeof(path), size, "resv_hugepages");

-       return read_num(path);
+       ret = read_num(path, &nr);
+       if (ret) {
+               print_file_access_error(path, ret);
+               exit(EXIT_FAILURE);
+       }
+
+       return nr;
 }

 static bool __hugetlb_setup(unsigned long size, unsigned long nr)
-- 
2.53.0

Reply via email to