From patchwork Thu Nov 4 13:35:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12603125 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45976C433F5 for ; Thu, 4 Nov 2021 13:35:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E8B3C61183 for ; Thu, 4 Nov 2021 13:35:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E8B3C61183 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3B6BE6B006C; Thu, 4 Nov 2021 09:35:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 36521940007; Thu, 4 Nov 2021 09:35:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27BAC6B0073; Thu, 4 Nov 2021 09:35:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id 182D96B006C for ; Thu, 4 Nov 2021 09:35:56 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C31495D71A for ; Thu, 4 Nov 2021 13:35:55 +0000 (UTC) X-FDA: 78771345870.22.90BD7D1 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf16.hostedemail.com (Postfix) with ESMTP id 72B04F00008C for ; Thu, 4 Nov 2021 13:35:47 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 377C561108; Thu, 4 Nov 2021 13:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636032954; bh=OfNAx9rQwiK+QscXJpdjavO2stFix0dG6j0x3xEKe1Q=; h=From:To:Cc:Subject:Date:From; b=RVwruqXOchb8HPnX9zYesjc5taffYzUjt7Ru/SD0ohD4UwUbooowtwoIEJPTiuRIV IKwwp2rfndBuNSLtgY/JjNhXQCExn0GZRbkzR+l30BdDCOOTJG0kHY0iqqYiHWJSNg GvgTwB99X/O68fnjRVr9IMIrHSBO0b9xG2WcXLBr3mkZ0t/Byfce148xWoj6fHuCWL 8XawY1nWvhDKfpPaNCakCh1OTddYg8NaMxoBoTpMcEkeSguYgDDoBD/pLAZoVIYajs /5CNVLT0BdybSBmlu0SzRe7GCGlRV6go/ehR2J2mm1y6x4VwjdB1p71cTfOLE0biVg NxcuD+n38m5Zg== From: Arnd Bergmann To: Andrew Morton Cc: Arnd Bergmann , "Uladzislau Rezki (Sony)" , Stephen Rothwell , Nicholas Piggin , Michal Hocko , "Paul E. McKenney" , Chen Wandun , David Hildenbrand , 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 Message-Id: <20211104133549.1150058-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Stat-Signature: dk5tj6kgni393xwr6tasrb994nudwbu4 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 72B04F00008C Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RVwruqXO; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of arnd@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=arnd@kernel.org X-HE-Tag: 1636032947-713426 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Arnd Bergmann 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 --- 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; }