]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/mm: check file initialization writes in split_huge_page_test
authorVineet Agarwal <agarwal.vineet2006@gmail.com>
Tue, 12 May 2026 07:49:24 +0000 (13:19 +0530)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 2 Jun 2026 22:22:12 +0000 (15:22 -0700)
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>
tools/testing/selftests/mm/split_huge_page_test.c

index 500d07c4938b184db9add3d0729bd31d3e066420..a8725942ee51b08773697816979b7981ca5669ec 100644 (file)
@@ -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);