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 <[email protected]>
---
 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


Reply via email to