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>
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);