mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
selftests/mm: fix read_file() return value check
read_file() returns 0 on open/read failures and never returns negative
values. Existing < 0 error checks never trigger, so read failures are
silently ignored. Check for zero return to detect read_file() failures.
Also fix misleading error message in get_finfo(). The error string
incorrectly references read_num when reading uevent files.
Link: https://lore.kernel.org/20260807013555.36525-1-hongfu.li@linux.dev
Fixes: e0c13f9761 ("khugepaged: add self test")
Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
34e0849142
commit
4050b5b0b6
|
|
@ -141,8 +141,8 @@ static void get_finfo(const char *dir)
|
|||
major(path_stat.st_dev), minor(path_stat.st_dev))
|
||||
>= sizeof(path))
|
||||
ksft_exit_fail_msg("%s: Pathname is too long\n", __func__);
|
||||
if (read_file(path, buf, sizeof(buf)) < 0)
|
||||
ksft_exit_fail_perror("read_file(read_num)");
|
||||
if (!read_file(path, buf, sizeof(buf)))
|
||||
ksft_exit_fail_perror("read_file(uevent)");
|
||||
if (strstr(buf, "DEVTYPE=disk")) {
|
||||
/* Found it */
|
||||
if (snprintf(finfo.dev_queue_read_ahead_path,
|
||||
|
|
|
|||
|
|
@ -942,7 +942,7 @@ unsigned long read_num(const char *path)
|
|||
{
|
||||
char buf[21];
|
||||
|
||||
if (read_file(path, buf, sizeof(buf)) < 0)
|
||||
if (!read_file(path, buf, sizeof(buf)))
|
||||
ksft_exit_fail_perror("read_file()");
|
||||
|
||||
return strtoul(buf, NULL, 10);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user