From patchwork Tue Feb 1 19:29:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 12732192 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 5362BC433FE for ; Tue, 1 Feb 2022 19:30:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75B398D0082; Tue, 1 Feb 2022 14:30:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7086A8D0077; Tue, 1 Feb 2022 14:30:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D0368D0082; Tue, 1 Feb 2022 14:30:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id 4922B8D0077 for ; Tue, 1 Feb 2022 14:30:03 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F03E082C5540 for ; Tue, 1 Feb 2022 19:30:02 +0000 (UTC) X-FDA: 79095201444.12.67F566A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 53495120008 for ; Tue, 1 Feb 2022 19:30:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643743801; 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=2TUBdCrGSJU9MaqKZxC4f3nHFAhGE9a8IWKYk+qvWfY=; b=FB+VfACQ9NaYNXCkW3yrEVf/IoQh0/a7CQz7DQh3iY7CuCsryrtgQF2lSl09zrwxvv1j5z Ft5SREb5gYElWbrFDhY992S1Sz3f6c0vHLiYPmyZfnBb7+xo1am9kykafLxz+RT7j261CH 7EIK1Yyd8Jhsj4hI6Ssis4xbvANj9bQ= 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-637-HBvz2wbnM5eewPRhg4YVDg-1; Tue, 01 Feb 2022 14:29:58 -0500 X-MC-Unique: HBvz2wbnM5eewPRhg4YVDg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5397A1054F91; Tue, 1 Feb 2022 19:29:57 +0000 (UTC) Received: from llong.com (unknown [10.22.19.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2E9719C59; Tue, 1 Feb 2022 19:29:39 +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] mm/sparsemem: Fix 'mem_section' will never be NULL gcc 12 warning Date: Tue, 1 Feb 2022 14:29:24 -0500 Message-Id: <20220201192924.672675-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Stat-Signature: fsrn3zcsoezb9ojagqjctdzsjatp1ngp X-Rspam-User: nil Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FB+VfACQ; spf=none (imf29.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 53495120008 X-HE-Tag: 1643743802-842206 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 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 : With CONFIG_SPARSEMEM_EXTREME on, the mem_section definition is extern struct mem_section **mem_section; Obviously, mem_section cannot be NULL, but *mem_section can be if memory hasn't been allocated for the dynamic mem_section[] array yet. Fix this warning by checking for "!*mem_section" instead. Fixes: 83e3c48729d9 ("mm/sparsemem: Allocate mem_section at runtime for CONFIG_SPARSEMEM_EXTREME=y") Signed-off-by: Waiman Long Reported-by: Justin Forbes --- include/linux/mmzone.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index aed44e9b5d89..bd1b19925f3b 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1390,7 +1390,7 @@ 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) return NULL; #endif if (!mem_section[SECTION_NR_TO_ROOT(nr)])