From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Vineet Agarwal <agarwal.vineet2006@gmail.com>, akpm@linux-foundation.org
Cc: ljs@kernel.org, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/mm: check file initialization writes in split_huge_page_test
Date: Tue, 12 May 2026 09:57:46 +0200 [thread overview]
Message-ID: <da82de92-29d8-457c-9f65-40fc4900b922@kernel.org> (raw)
In-Reply-To: <20260512074924.27721-1-agarwal.vineet2006@gmail.com>
On 5/12/26 09:49, Vineet Agarwal wrote:
> 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.
>
> Signed-off-by: Vineet Agarwal <agarwal.vineet2006@gmail.com>
> ---
> tools/testing/selftests/mm/split_huge_page_test.c | 13 ++++++++++---
> 1 file changed, 10 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 500d07c4938b..eab69b0f59a0 100644
> --- a/tools/testing/selftests/mm/split_huge_page_test.c
> +++ b/tools/testing/selftests/mm/split_huge_page_test.c
> @@ -609,9 +609,16 @@ 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)) {
> + ssize_t written;
Do you really need the temporary variable?
> +
> + written = write(*fd, buf, sizeof(buf));
> + if (written != sizeof(buf)) {
> + ksft_perror("write testfile");
> + close(*fd);
> + goto err_out_unlink;
> + }
> + }
> close(*fd);
> sync();
> *fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
Apart from that LGTM
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
prev parent reply other threads:[~2026-05-12 7:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 7:49 [PATCH] selftests/mm: check file initialization writes in split_huge_page_test Vineet Agarwal
2026-05-12 7:57 ` David Hildenbrand (Arm) [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=da82de92-29d8-457c-9f65-40fc4900b922@kernel.org \
--to=david@kernel.org \
--cc=agarwal.vineet2006@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox