Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2193646iof; Tue, 7 Jun 2022 22:47:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAWSBLpVs6ZFSp0q6PCsEvNsgXCJSnwbqefOjHe8VDx8XEmS/vuJJropcD+ycA5HRLOLIv X-Received: by 2002:a17:902:eb85:b0:167:8dcb:2003 with SMTP id q5-20020a170902eb8500b001678dcb2003mr8920909plg.121.1654667261455; Tue, 07 Jun 2022 22:47:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667261; cv=none; d=google.com; s=arc-20160816; b=CR72xsx1f10T7dGiHlMj6QA0GM5C9Azt9uOa4bRvXzH6QcU9yFuKhfN8kTg8g3xy22 aowzG7LdpYum+lqrsIbPXX+0CE0xTf2qzIF3tvig53ZK0QMfarvC+rkAzXBftan+d4bk JZoRS8pfKLbyy5pnqm4zZYDdbOPUVUrk0anzj/esfnvTgpOkrSQbVpvptQKHE+iWfngE PQ/JJUP+OuJfeOt4jHaBihpjwPFtEzUSvkVPpk8SrRRqWQaUiK2Bnko3C4SUNFhdzCSx Fjmlk1RGqTbawKY6kmh5NPVIqs9NpcKpASJCRlRqhhNOi33vlDh95KgW4tl3YJTdOGw7 8meg== 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=5cqm8vT9jgaWMW8oLfECpt1SxZdjnT7gjlB9tWrOIuM=; b=U5e8NPyY3Fe1rxoi3EML/NUW5TpXPk0bZ6dEeI8S9t632p/qEgc5t6TOcP+J9jQm3o Xd76JAx+Vl3Mi912Ejt7ZO00ZGWOzajI8195FvhLi7Wl6m3Ynihgq42/XDbumZ2q6I+D kYBkBnwr94wU4sHb0dj23k6eZiHBEcg15vSKbFi4QbFDgBBlx9U6TmZiY6zZ3TeZct9R npxKwh33NYi5tondlrTJrZy5vHYp+poY5eAh+m3hw/IJMaZppoQzRfbyUFAtqlGc+8Xv JnmQClNYG1jeUjhJEyix4OHC47fXJKDCQCnLDKSXQjqgAqWDiqyQnFy4gX+hBdi4qQ0j Ugiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NJj62ezh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m8-20020a170902db0800b0015a16b86c56si28931924plx.81.2022.06.07.22.47.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:47:41 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NJj62ezh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3C50149CFAC; Tue, 7 Jun 2022 22:12:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387763AbiFHAar (ORCPT + 99 others); Tue, 7 Jun 2022 20:30:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381637AbiFGW3l (ORCPT ); Tue, 7 Jun 2022 18:29:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF1D5274D53; Tue, 7 Jun 2022 12:23:50 -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 D26E8B823CC; Tue, 7 Jun 2022 19:23:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 073ECC385A2; Tue, 7 Jun 2022 19:23:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629827; bh=1deBv8pWO4EhlblSV+d3qc0OS1zA34siQuYQ1ppkR98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NJj62ezhD1Cs/XBtPm6WLTPKjqfjOjtbUPr5nsMhFqqn3SltjKffdq+BgLFphQB1S 1Ci7gQrbjKy7tS1wUh419QHCzpuI0GGWew6gu4OqLZveTb7tSWNgdmWC01EuiQjKrd M9irQ5a+8sfCn8io1nmC7rOeZkIh72nikNH+6I2k= 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 5.18 831/879] nodemask.h: fix compilation error with GCC12 Date: Tue, 7 Jun 2022 19:05:49 +0200 Message-Id: <20220607165026.976043805@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 @@ -375,14 +375,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 */ /*