aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
authorVineet Agarwal <agarwal.vineet2006@gmail.com>2026-05-12 13:19:24 +0530
committerAndrew Morton <akpm@linux-foundation.org>2026-05-28 21:30:58 -0700
commitf427282090e04081b308b20dae39e671eac69ded (patch)
treea1250ac9bd724d50b524120bd73747414e717db9 /tools
parente8a59cef8e4a9dc744fe414ee1271cd75fbaf1c4 (diff)
downloadlinux-next-history-f427282090e04081b308b20dae39e671eac69ded.tar.gz
selftests/mm: check file initialization writes in split_huge_page_test
create_pagecache_thp_and_fd() fills the backing file for the pagecache THP tests using repeated write() calls, but the return value is never checked. If a write fails or completes only partially, the test may continue with an incompletely initialized file and produce misleading results. Check the result of write() and fail the test if the expected number of bytes was not written. [akpm@linux-foundation.org: remove unneeded local, per David] Link: https://lore.kernel.org/da82de92-29d8-457c-9f65-40fc4900b922@kernel.org Link: https://lore.kernel.org/20260512074924.27721-1-agarwal.vineet2006@gmail.com Signed-off-by: Vineet Agarwal <agarwal.vineet2006@gmail.com> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Wei Yang <richard.weiyang@gmail.com> Cc: Vineet Agarwal <agarwal.vineet2006@gmail.com> Cc: Lorenzo Stoakes <ljs@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/mm/split_huge_page_test.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index 500d07c4938b1..a8725942ee51b 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -609,9 +609,13 @@ static int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size,
assert(fd_size % sizeof(buf) == 0);
for (i = 0; i < sizeof(buf); i++)
buf[i] = (unsigned char)i;
- for (i = 0; i < fd_size; i += sizeof(buf))
- write(*fd, buf, sizeof(buf));
-
+ for (i = 0; i < fd_size; i += sizeof(buf)) {
+ if (write(*fd, buf, sizeof(buf)) != sizeof(buf)) {
+ ksft_perror("write testfile");
+ close(*fd);
+ goto err_out_unlink;
+ }
+ }
close(*fd);
sync();
*fd = open("/proc/sys/vm/drop_caches", O_WRONLY);