Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Wake Liu <wakel@google.com>
Cc: David Hildenbrand <david@redhat.com>,
	Shuah Khan <shuah@kernel.org>,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>, Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Ankit Khushwaha <ankitkhushwaha.linux@gmail.com>
Subject: Re: [PATCH] mm/selftests: Fix -Wtautological-compare warning in mremap_test.c
Date: Mon, 10 Nov 2025 10:09:14 -0800	[thread overview]
Message-ID: <20251110100914.af77cb0a5b4211313dd9f32a@linux-foundation.org> (raw)
In-Reply-To: <20251110175155.1314757-1-wakel@google.com>

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?


      reply	other threads:[~2025-11-10 18:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 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=20251110100914.af77cb0a5b4211313dd9f32a@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=ankitkhushwaha.linux@gmail.com \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=wakel@google.com \
    /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