From patchwork Wed Feb 2 00:35:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 12732469 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 411C1C433F5 for ; Wed, 2 Feb 2022 00:37:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BBB38D009A; Tue, 1 Feb 2022 19:37:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 86B368D0094; Tue, 1 Feb 2022 19:37:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70BD38D009A; Tue, 1 Feb 2022 19:37:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id 628988D0094 for ; Tue, 1 Feb 2022 19:37:15 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0F57C972EB for ; Wed, 2 Feb 2022 00:37:15 +0000 (UTC) X-FDA: 79095975630.30.D5374CF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id A694A1A0003 for ; Wed, 2 Feb 2022 00:37:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643762234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=kcWuqd5evricJIxS6cUHjNVZ199P8EXWi5nJ6wTm+mw=; b=RgvMUlChQZ1cSf3ch/7+GH+0RnN4LgZcTZaH5QAUehOjO5LF2PVkQR1ckBduFcJ5biKFJr RGt7MP8JG3x550L7GJInofnXUgpj6ymYrEpuznG9mg9/h8f7/INjJTZ1opTS23R0FhieCs Rs++ONo/XfWh16QbT+XUj2c7KyiMqhE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-104-HJoyl65mNLytNk4FbvMUZQ-1; Tue, 01 Feb 2022 19:37:10 -0500 X-MC-Unique: HJoyl65mNLytNk4FbvMUZQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A01A11124C40; Wed, 2 Feb 2022 00:37:09 +0000 (UTC) Received: from llong.com (unknown [10.22.19.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 688FD105C74E; Wed, 2 Feb 2022 00:36:52 +0000 (UTC) From: Waiman Long To: Andrew Morton , "Kirill A. Shutemov" , Ingo Molnar Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Justin Forbes , Rafael Aquini , Waiman Long Subject: [PATCH v2] mm/sparsemem: Fix 'mem_section' will never be NULL gcc 12 warning Date: Tue, 1 Feb 2022 19:35:50 -0500 Message-Id: <20220202003550.698768-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Stat-Signature: ow7aacmmzsgsnkjx4dupnmp5wocknnty X-Rspam-User: nil Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RgvMUlCh; spf=none (imf19.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A694A1A0003 X-HE-Tag: 1643762234-100382 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: The gcc 12 compiler reports a "'mem_section' will never be NULL" warning on the following code: static inline struct mem_section *__nr_to_section(unsigned long nr) { #ifdef CONFIG_SPARSEMEM_EXTREME if (!mem_section) return NULL; #endif if (!mem_section[SECTION_NR_TO_ROOT(nr)]) return NULL; : It happens with both CONFIG_SPARSEMEM_EXTREME on and off. The mem_section definition is #ifdef CONFIG_SPARSEMEM_EXTREME extern struct mem_section **mem_section; #else extern struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT]; #endif In the CONFIG_SPARSEMEM_EXTREME case, mem_section obviously cannot be NULL, but *mem_section can be if memory hasn't been allocated for the dynamic mem_section[] array yet. In the !CONFIG_SPARSEMEM_EXTREME case, mem_section is a static 2-dimensional array and so the check "!mem_section[SECTION_NR_TO_ROOT(nr)]" doesn't make sense. Fix this warning by checking for "!*mem_section" instead of "!mem_section" and moving the "!mem_section[SECTION_NR_TO_ROOT(nr)]" check up inside the CONFIG_SPARSEMEM_EXTREME block. Fixes: 83e3c48729d9 ("mm/sparsemem: Allocate mem_section at runtime for CONFIG_SPARSEMEM_EXTREME=y") Fixes: 3e347261a80b ("sparsemem extreme implementation") Reported-by: Justin Forbes Signed-off-by: Waiman Long --- include/linux/mmzone.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index aed44e9b5d89..08517376c765 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1390,11 +1390,9 @@ static inline unsigned long *section_to_usemap(struct mem_section *ms) static inline struct mem_section *__nr_to_section(unsigned long nr) { #ifdef CONFIG_SPARSEMEM_EXTREME - if (!mem_section) + if (!*mem_section || !mem_section[SECTION_NR_TO_ROOT(nr)]) return NULL; #endif - if (!mem_section[SECTION_NR_TO_ROOT(nr)]) - return NULL; return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK]; } extern size_t mem_section_usage_size(void);