* [PATCH] mm/selftests: Fix -Wtautological-compare warning in mremap_test.c
@ 2025-11-10 17:51 Wake Liu
2025-11-10 18:09 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Wake Liu @ 2025-11-10 17:51 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand, Shuah Khan, linux-mm,
linux-kselftest, linux-kernel
Cc: Lorenzo Stoakes, Liam R . Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Wake Liu
The compiler warns about a tautological comparison in mremap_test.c:
"pointer comparison always evaluates to false [-Wtautological-compare]"
This occurs when checking for unsigned overflow:
if (addr + c.dest_alignment < addr)
Cast 'addr' to 'unsigned long long' to ensure the comparison is performed
with a wider type, correctly detecting potential overflow and resolving
the warning.
Signed-off-by: Wake Liu <wakel@google.com>
---
tools/testing/selftests/mm/mremap_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c
index bf2863b102e3..c4933f4cbd48 100644
--- a/tools/testing/selftests/mm/mremap_test.c
+++ b/tools/testing/selftests/mm/mremap_test.c
@@ -1032,7 +1032,7 @@ static long long remap_region(struct config c, unsigned int threshold_mb,
/* Don't destroy existing mappings unless expected to overlap */
while (!is_remap_region_valid(addr, c.region_size) && !c.overlapping) {
/* Check for unsigned overflow */
- if (addr + c.dest_alignment < addr) {
+ if ((unsigned long long)addr + c.dest_alignment < (unsigned long long)addr) {
ksft_print_msg("Couldn't find a valid region to remap to\n");
ret = -1;
goto clean_up_src;
--
2.51.2.1041.gc1ab5b90ca-goog
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] mm/selftests: Fix -Wtautological-compare warning in mremap_test.c
2025-11-10 17:51 [PATCH] mm/selftests: Fix -Wtautological-compare warning in mremap_test.c Wake Liu
@ 2025-11-10 18:09 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2025-11-10 18:09 UTC (permalink / raw)
To: Wake Liu
Cc: David Hildenbrand, Shuah Khan, linux-mm, linux-kselftest,
linux-kernel, Lorenzo Stoakes, Liam R . Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Ankit Khushwaha
On Tue, 11 Nov 2025 01:51:55 +0800 Wake Liu <wakel@google.com> wrote:
> The compiler warns about a tautological comparison in mremap_test.c:
> "pointer comparison always evaluates to false [-Wtautological-compare]"
>
> This occurs when checking for unsigned overflow:
> if (addr + c.dest_alignment < addr)
>
> Cast 'addr' to 'unsigned long long' to ensure the comparison is performed
> with a wider type, correctly detecting potential overflow and resolving
> the warning.
>
Thanks. I recently merged
https://lore.kernel.org/all/20251108161829.25105-1-ankitkhushwaha.linux@gmail.com/T/#u
there has been some discussion...
> --- a/tools/testing/selftests/mm/mremap_test.c
> +++ b/tools/testing/selftests/mm/mremap_test.c
> @@ -1032,7 +1032,7 @@ static long long remap_region(struct config c, unsigned int threshold_mb,
> /* Don't destroy existing mappings unless expected to overlap */
> while (!is_remap_region_valid(addr, c.region_size) && !c.overlapping) {
> /* Check for unsigned overflow */
> - if (addr + c.dest_alignment < addr) {
> + if ((unsigned long long)addr + c.dest_alignment < (unsigned long long)addr) {
> ksft_print_msg("Couldn't find a valid region to remap to\n");
> ret = -1;
> goto clean_up_src;
I wonder if we'd be better off borrowing ideas from
include/linux/overflow.h:check_add_overflow(). Did anyone try
__builtin_add_overflow() here?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-10 18:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-10 17:51 [PATCH] mm/selftests: Fix -Wtautological-compare warning in mremap_test.c Wake Liu
2025-11-10 18:09 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox