From patchwork Wed Mar 30 20:59:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 12796363 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 64214C433EF for ; Wed, 30 Mar 2022 20:59:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BAF728D0001; Wed, 30 Mar 2022 16:59:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B61526B0073; Wed, 30 Mar 2022 16:59:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FF4D8D0001; Wed, 30 Mar 2022 16:59:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0198.hostedemail.com [216.40.44.198]) by kanga.kvack.org (Postfix) with ESMTP id 8D5A56B0072 for ; Wed, 30 Mar 2022 16:59:33 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 44EF61828AC6E for ; Wed, 30 Mar 2022 20:59:33 +0000 (UTC) X-FDA: 79302268626.31.1DF4C58 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id C8DC2C000B for ; Wed, 30 Mar 2022 20:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648673972; 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=Sy8bkqtPJSZgcyuTbRCJfF/i6zL7BC/uXgP8JV+OWLU=; b=ISlRZriKe3It6cbqgrJ5AnXhDCPN3+C2mwsHbnk5FHJ6zeNRSBLPVQJuG0qwXS71Rl2NVO AZ4kTDd/iddfyh7w3i5QqhBoMwLWk5pvGMi730m8bBy1qjprJXLMWsORbLx8kA+JtNFiNm VgqEbifSfijHkONoleZGXJkxLtUbHqY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-626-ji24S9IEPZaTOciUVy2QlA-1; Wed, 30 Mar 2022 16:59:30 -0400 X-MC-Unique: ji24S9IEPZaTOciUVy2QlA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1F6B985A5BE; Wed, 30 Mar 2022 20:59:30 +0000 (UTC) Received: from llong.com (dhcp-17-215.bos.redhat.com [10.18.17.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id D18C140CF8E4; Wed, 30 Mar 2022 20:59:29 +0000 (UTC) From: Waiman Long To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A . Shutemov" , Ingo Molnar , Justin Forbes , Rafael Aquini , Waiman Long Subject: [PATCH v3] mm/sparsemem: Fix 'mem_section' will never be NULL gcc 12 warning Date: Wed, 30 Mar 2022 16:59:19 -0400 Message-Id: <20220330205919.2713275-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ISlRZriK; spf=none (imf10.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-Stat-Signature: t49icjh6rheq6aj6f7gt1xznd3hdx4bg X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C8DC2C000B X-HE-Tag: 1648673972-419685 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 CONFIG_SPARSEMEM_EXTREME 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 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 moving the "!mem_section[SECTION_NR_TO_ROOT(nr)]" check up inside the CONFIG_SPARSEMEM_EXTREME block. Fixes: 3e347261a80b ("sparsemem extreme implementation") Reported-by: Justin Forbes Signed-off-by: Waiman Long Reported-by: kernel test robot --- 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 962b14d403e8..8a89efe47571 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1398,11 +1398,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);