From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAD1CC47088 for ; Wed, 26 May 2021 19:36:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9959861186 for ; Wed, 26 May 2021 19:36:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233605AbhEZTiK (ORCPT ); Wed, 26 May 2021 15:38:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28991 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbhEZTiF (ORCPT ); Wed, 26 May 2021 15:38:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622057791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lvXIzW1vboiHDAOnYTe4b5RTNGtYwyUKmFA6LenTEYg=; b=XzjstuFw0W+1Gegcc64NyEjxfe+peoxq/ghdk3LAg+7TUEfxd+o41+1rmPTuXfOvKg6o8P QoKzzeWlXlzAkX//WI5gRdklqKeeMksmu4N/hgO+zTlLpgV7LLuoEWjwf4d6eCL9cjDrRH poIhyAJ//1ZjpwkC/DUdHtEBO87asu8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-431-8fnfKFh9MMuYF7AksyzIIg-1; Wed, 26 May 2021 15:36:27 -0400 X-MC-Unique: 8fnfKFh9MMuYF7AksyzIIg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4E40180FD69; Wed, 26 May 2021 19:36:25 +0000 (UTC) Received: from llong.com (ovpn-112-32.rdu2.redhat.com [10.10.112.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65D345D723; Wed, 26 May 2021 19:36:21 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Muchun Song , Waiman Long Subject: [PATCH-next] mm/memcontrol.c: Fix potential uninitialized variable warning Date: Wed, 26 May 2021 15:36:02 -0400 Message-Id: <20210526193602.8742-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the -Wno-maybe-uninitialized gcc option is not specified, compilation of memcontrol.c may generate the following warnings: mm/memcontrol.c: In function ‘refill_obj_stock’: ./arch/x86/include/asm/irqflags.h:127:17: warning: ‘flags’ may be used uninitialized in this function [-Wmaybe-uninitialized] return !(flags & X86_EFLAGS_IF); ~~~~~~~^~~~~~~~~~~~~~~~ mm/memcontrol.c:3216:16: note: ‘flags’ was declared here unsigned long flags; ^~~~~ In file included from mm/memcontrol.c:29: mm/memcontrol.c: In function ‘uncharge_page’: ./include/linux/memcontrol.h:797:2: warning: ‘objcg’ may be used uninitialized in this function [-Wmaybe-uninitialized] percpu_ref_put(&objcg->refcnt); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fix that by properly initializing *pflags in get_obj_stock() and introducing a use_objcg bool variable in uncharge_page() to avoid potentially accessing the struct page data twice. Signed-off-by: Waiman Long --- mm/memcontrol.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index cb864f87b01d..b9a6db6a7d4f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2108,6 +2108,7 @@ static inline struct obj_stock *get_obj_stock(unsigned long *pflags) struct memcg_stock_pcp *stock; if (likely(in_task())) { + *pflags = 0UL; preempt_disable(); stock = this_cpu_ptr(&memcg_stock); return &stock->task_obj; @@ -6840,6 +6841,7 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) unsigned long nr_pages; struct mem_cgroup *memcg; struct obj_cgroup *objcg; + bool use_objcg = PageMemcgKmem(page); VM_BUG_ON_PAGE(PageLRU(page), page); @@ -6848,7 +6850,7 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) * page memcg or objcg at this point, we have fully * exclusive access to the page. */ - if (PageMemcgKmem(page)) { + if (use_objcg) { objcg = __page_objcg(page); /* * This get matches the put at the end of the function and @@ -6876,7 +6878,7 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) nr_pages = compound_nr(page); - if (PageMemcgKmem(page)) { + if (use_objcg) { ug->nr_memory += nr_pages; ug->nr_kmem += nr_pages; -- 2.18.1