linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	"Uladzislau Rezki (Sony)" <urezki@gmail.com>,
	Stephen Rothwell <sfr@canb.auug.org.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	Michal Hocko <mhocko@suse.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Chen Wandun <chenwandun@huawei.com>,
	David Hildenbrand <david@redhat.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mm: vmap: avoid -Wsequence-point warning
Date: Thu,  4 Nov 2021 14:35:40 +0100	[thread overview]
Message-ID: <20211104133549.1150058-1-arnd@kernel.org> (raw)

From: Arnd Bergmann <arnd@arndb.de>

gcc warns about potentially undefined behavior in an array index:

mm/vmalloc.c: In function 'vmap_pfn_apply':
mm/vmalloc.c:2800:58: error: operation on 'data->idx' may be undefined [-Werror=sequence-point]
 2800 |         *pte = pte_mkspecial(pfn_pte(data->pfns[data->idx++], data->prot));
      |                                                 ~~~~~~~~~^~
arch/arm64/include/asm/pgtable-types.h:25:37: note: in definition of macro '__pte'
   25 | #define __pte(x)        ((pte_t) { (x) } )
      |                                     ^
arch/arm64/include/asm/pgtable.h:80:15: note: in expansion of macro '__phys_to_pte_val'
   80 |         __pte(__phys_to_pte_val((phys_addr_t)(pfn) << PAGE_SHIFT) | pgprot_val(prot))
      |               ^~~~~~~~~~~~~~~~~
mm/vmalloc.c:2800:30: note: in expansion of macro 'pfn_pte'
 2800 |         *pte = pte_mkspecial(pfn_pte(data->pfns[data->idx++], data->prot));
      |                              ^~~~~~~

This only appeared in one randconfig build so far, and I don't know
what caused it, but moving the index increment out of the expression
at least addresses the warning.

Fixes: 3e9a9e256b1e ("mm: add a vmap_pfn function")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
Not sure if it's worth doing a deeper analysis of how the compiler
thinks this might go wrong, it would appear that it thinks 'pte'
might be an alias for 'data' here, but only in some configurations.

If you want to try reproducing it, the .config that triggered it is
https://pastebin.com/caeKD1Wv
---
 mm/vmalloc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index d2a00ad4e1dd..cdac02aab6b1 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2797,7 +2797,9 @@ static int vmap_pfn_apply(pte_t *pte, unsigned long addr, void *private)
 
 	if (WARN_ON_ONCE(pfn_valid(data->pfns[data->idx])))
 		return -EINVAL;
-	*pte = pte_mkspecial(pfn_pte(data->pfns[data->idx++], data->prot));
+	*pte = pte_mkspecial(pfn_pte(data->pfns[data->idx], data->prot));
+	data->idx++;
+
 	return 0;
 }
 
-- 
2.29.2



             reply	other threads:[~2021-11-04 13:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04 13:35 Arnd Bergmann [this message]
2021-11-04 13:57 ` Matthew Wilcox
2021-11-04 14:39   ` Arnd Bergmann

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=20211104133549.1150058-1-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=chenwandun@huawei.com \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=npiggin@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=sfr@canb.auug.org.au \
    --cc=urezki@gmail.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