mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: Drop the unsigned >= 0 assertions in test_write/test_read
@ 2026-09-17 18:10 Gokul K
  2026-09-17 20:28 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Gokul K @ 2026-09-17 18:10 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, kvm
  Cc: Shuah Khan, linux-kselftest, linux-kernel

test_write() and test_read() both open with

	TEST_ASSERT(count >= 0, "Unexpected count, count: %li", count);

but @count is a size_t, so the condition is always true and the assertion
can never fire. Building the selftests with -Wextra says so:

  lib/io.c:51:27: warning: comparison of unsigned expression in '>= 0'
                  is always true [-Wtype-limits]
  lib/io.c:128:27: warning: comparison of unsigned expression in '>= 0'
                  is always true [-Wtype-limits]

@count has been a size_t since these helpers were added in commit
6089ae0bd5e1 ("kvm: selftests: add sync_regs_test"), so this has never
guarded anything; nothing regressed and there is no behavioural change.

Note also that the message the assertion would have printed is wrong: %li
takes a long, not a size_t. That has gone unnoticed precisely because the
assertion is unreachable, which is a fair summary of the value it adds.

Delete both. The comment above each one is about a count of zero being
legitimate, which remains true and is worth keeping.

Signed-off-by: Gokul K <gokul02k@gmail.com>
---
 tools/testing/selftests/kvm/lib/io.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/lib/io.c b/tools/testing/selftests/kvm/lib/io.c
index fedb2a741f0b..356586250595 100644
--- a/tools/testing/selftests/kvm/lib/io.c
+++ b/tools/testing/selftests/kvm/lib/io.c
@@ -48,7 +48,6 @@ ssize_t test_write(int fd, const void *buf, size_t count)
 	/* Note: Count of zero is allowed (see "RETURN VALUE" portion of
 	 * write(2) manpage for details.
 	 */
-	TEST_ASSERT(count >= 0, "Unexpected count, count: %li", count);
 
 	do {
 		rc = write(fd, ptr, num_left);
@@ -125,7 +124,6 @@ ssize_t test_read(int fd, void *buf, size_t count)
 	/* Note: Count of zero is allowed (see "If count is zero" portion of
 	 * read(2) manpage for details.
 	 */
-	TEST_ASSERT(count >= 0, "Unexpected count, count: %li", count);
 
 	do {
 		rc = read(fd, ptr, num_left);
-- 
2.54.0



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-17 20:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 18:10 [PATCH] KVM: selftests: Drop the unsigned >= 0 assertions in test_write/test_read Gokul K
2026-09-17 20:28 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®