On 8/25/26 11:05, Usama Anjum wrote:
> On 13/08/2026 7:12 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. 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.
>>
>> Signed-off-by: Sarthak Sharma <[email protected]>
>> ---
>>  .../testing/selftests/mm/hugepage_settings.c  |  98 +++++++++++---
>>  tools/testing/selftests/mm/khugepaged.c       |  14 +-
>>  .../selftests/mm/split_huge_page_test.c       |   5 +-
>>  tools/testing/selftests/mm/vm_util.c          | 120 ++++++++++++------
>>  tools/testing/selftests/mm/vm_util.h          |   8 +-
>>  5 files changed, 178 insertions(+), 67 deletions(-)
>>
>> diff --git a/tools/testing/selftests/mm/hugepage_settings.c 
>> b/tools/testing/selftests/mm/hugepage_settings.c
>> index d7917dce3aba..5bcda01ac4f6 100644
>> --- a/tools/testing/selftests/mm/hugepage_settings.c
>> +++ b/tools/testing/selftests/mm/hugepage_settings.c
>> @@ -8,6 +8,7 @@
>>  #include <stdlib.h>
>>  #include <string.h>
>>  #include <unistd.h>
>> +#include <errno.h>
>>  
>>  #include "vm_util.h"
>>  #include "hugepage_settings.h"
>> @@ -48,6 +49,11 @@ static const char * const shmem_enabled_strings[] = {
>>      NULL
>>  };
>>  
>> +static void print_file_access_error(const char *path, int ret)
>> +{
>> +    printf("# %s: %s (%d)\n", path, strerror(-ret), -ret);
> ksft_print_msg() is what you want here. It adds # by default.

That code is getting moved out of tools/testing/selftests/mm in a later commit.

(see "This prepares the helpers to be moved to tools/lib/mm without a kselftest
dependency.") above.

-- 
Cheers,

David

Reply via email to