Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp446545iog; Mon, 13 Jun 2022 06:09:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+G8piGUa+qjop/qhGeg+X4QX/hkW/pNfmNq0xUfBF8c5NKuKyWKK3OKIvmib9+so4w0CQ X-Received: by 2002:a63:1411:0:b0:402:de25:6c0a with SMTP id u17-20020a631411000000b00402de256c0amr15215517pgl.501.1655125635165; Mon, 13 Jun 2022 06:07:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125635; cv=none; d=google.com; s=arc-20160816; b=yxIZdpNLL8JwNfQfP18a4UaJHc9bsegmCY4Ir5LpNNbfedHmNCCp4vvJzG3U7WdLMz gs0wuzkNkpSrS2F+UW79hayuhxKuusSNAC8y0JdKBu+7wjN8HHA8Gl0pxxdeoC/5aLgM /WnPqWn5/02G47HOfavI/3gZCLsa5bDEB9HVBNgPAdI8+6akmhYUMcYyUvyzv1bwVaNu UWDe4FV2QaLLV3OXWVhajJMRS62hpgZVTJnAN6yzK1l2eGxII4JsN0yG+waJ785deuuL t59e4cu2JKuHuyW79cRakui6Fz9bFmgRsjiDltE4wwugqEIXV/6JpZnH2NTnzk3p/IHq QCSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/ToSTM2BdnZu5IKtjencq8n0TUBqBsSsX2xPkpHxslY=; b=myfIGzFoAu2Qy/Glv5bX3reH2zQ73jguxbS42gIPE8RQJxzILaSGjdOt0GqsSJdhC1 z1IOKi1m9wcFvrEDiH1hV3f5fGWS1bb4KLrm4DFvY6M8yjoYNA4HARaytHjfdI5vUD1w 74vH3UbyvDpmMGcEbs1TWiqhI1YFtnmCQ8IUq2WL99y8gUqJBBxGHhL1sgkJmf8lX2IS 71U9VQ9F7SV66Fs2Zq1tiguAsA/DwLrFvpKu0IpP8a+HART1tjdtH+WaNywz+RW8yI7l oqirrneFkOkWgX92AE5xY8ewnEt+UCFu1jmXFO/bPDVpGG6leNz2PFY2dabVOPP3da/O pZyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C47gfPAv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z24-20020a630a58000000b003fdd5d90ee5si9328699pgk.740.2022.06.13.06.06.58; Mon, 13 Jun 2022 06:07:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C47gfPAv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349724AbiFMK5t (ORCPT + 99 others); Mon, 13 Jun 2022 06:57:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350037AbiFMKyj (ORCPT ); Mon, 13 Jun 2022 06:54:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18704DFA3; Mon, 13 Jun 2022 03:28:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C5086B80E2D; Mon, 13 Jun 2022 10:28:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02227C3411E; Mon, 13 Jun 2022 10:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116115; bh=4h2v1TIq1NyGvoDQucJRSIgFfQr5k9QZfvY5QR5hwaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C47gfPAvgQ+9DojMBX6BLaGGclQiS26FK/r9TWZk4yDe0nEfGnEdO3sQ899HOHuVW sYFJaEje9vdcTGEOjrveTdaj4/lDzVRYsng1fnLqeSDK3sznxYgkoAwjblg3jGSkSI w0jSWp1d4WXXfhnB+a1iaBYAOH4ZI0PK5fZThs3c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe de Dinechin , Christophe de Dinechin , Andrew Morton , Ben Segall , "Michael S. Tsirkin" , Steven Rostedt , Ingo Molnar , Mel Gorman , Dietmar Eggemann , Vincent Guittot , Paolo Bonzini , Daniel Bristot de Oliveira , Jason Wang , Zhen Lei , Juri Lelli , Peter Zijlstra Subject: [PATCH 4.14 126/218] nodemask.h: fix compilation error with GCC12 Date: Mon, 13 Jun 2022 12:09:44 +0200 Message-Id: <20220613094924.395167677@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe de Dinechin commit 37462a920392cb86541650a6f4121155f11f1199 upstream. With gcc version 12.0.1 20220401 (Red Hat 12.0.1-0), building with defconfig results in the following compilation error: | CC mm/swapfile.o | mm/swapfile.c: In function `setup_swap_info': | mm/swapfile.c:2291:47: error: array subscript -1 is below array bounds | of `struct plist_node[]' [-Werror=array-bounds] | 2291 | p->avail_lists[i].prio = 1; | | ~~~~~~~~~~~~~~^~~ | In file included from mm/swapfile.c:16: | ./include/linux/swap.h:292:27: note: while referencing `avail_lists' | 292 | struct plist_node avail_lists[]; /* | | ^~~~~~~~~~~ This is due to the compiler detecting that the mask in node_states[__state] could theoretically be zero, which would lead to first_node() returning -1 through find_first_bit. I believe that the warning/error is legitimate. I first tried adding a test to check that the node mask is not emtpy, since a similar test exists in the case where MAX_NUMNODES == 1. However, adding the if statement causes other warnings to appear in for_each_cpu_node_but, because it introduces a dangling else ambiguity. And unfortunately, GCC is not smart enough to detect that the added test makes the case where (node) == -1 impossible, so it still complains with the same message. This is why I settled on replacing that with a harmless, but relatively useless (node) >= 0 test. Based on the warning for the dangling else, I also decided to fix the case where MAX_NUMNODES == 1 by moving the condition inside the for loop. It will still only be tested once. This ensures that the meaning of an else following for_each_node_mask or derivatives would not silently have a different meaning depending on the configuration. Link: https://lkml.kernel.org/r/20220414150855.2407137-3-dinechin@redhat.com Signed-off-by: Christophe de Dinechin Signed-off-by: Christophe de Dinechin Reviewed-by: Andrew Morton Cc: Ben Segall Cc: "Michael S. Tsirkin" Cc: Steven Rostedt Cc: Ingo Molnar Cc: Mel Gorman Cc: Dietmar Eggemann Cc: Vincent Guittot Cc: Paolo Bonzini Cc: Daniel Bristot de Oliveira Cc: Jason Wang Cc: Zhen Lei Cc: Juri Lelli Cc: Peter Zijlstra Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- include/linux/nodemask.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h @@ -366,14 +366,13 @@ static inline void __nodes_fold(nodemask } #if MAX_NUMNODES > 1 -#define for_each_node_mask(node, mask) \ - for ((node) = first_node(mask); \ - (node) < MAX_NUMNODES; \ - (node) = next_node((node), (mask))) +#define for_each_node_mask(node, mask) \ + for ((node) = first_node(mask); \ + (node >= 0) && (node) < MAX_NUMNODES; \ + (node) = next_node((node), (mask))) #else /* MAX_NUMNODES == 1 */ -#define for_each_node_mask(node, mask) \ - if (!nodes_empty(mask)) \ - for ((node) = 0; (node) < 1; (node)++) +#define for_each_node_mask(node, mask) \ + for ((node) = 0; (node) < 1 && !nodes_empty(mask); (node)++) #endif /* MAX_NUMNODES */ /*