On 8/13/26 20:12, 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]>
> ---
[...]
> -unsigned long read_num(const char *path)
> +int read_num(const char *path, unsigned long *num)
> {
> + unsigned long val;
> + int ret;
> char buf[21];
> + char *end;
>
> - if (!read_file(path, buf, sizeof(buf)))
> - ksft_exit_fail_perror("read_file()");
> + if (!num)
> + return -EINVAL;
>
> - return strtoul(buf, NULL, 10);
> + ret = read_file(path, buf, sizeof(buf));
> + if (ret)
> + return ret;
> +
> + if (buf[0] < '0' || buf[0] > '9')
> + return -EINVAL;
This is to reject any negative or hexadecimal numbers I assume?
(essentially anything that's not a valid number)
Worth adding a comment.
Apart from that LGTM
Acked-by: David Hildenbrand (Arm) <[email protected]>
--
Cheers,
David