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=-14.0 required=3.0 tests=BAYES_00,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 84D93C47089 for ; Thu, 27 May 2021 20:25:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2DD6F61360 for ; Thu, 27 May 2021 20:25:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DD6F61360 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A3BCD6B006E; Thu, 27 May 2021 16:24:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E2BF6B0070; Thu, 27 May 2021 16:24:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57C3D8D0001; Thu, 27 May 2021 16:24:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id 143F86B006E for ; Thu, 27 May 2021 16:24:59 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A6166181AF5CA for ; Thu, 27 May 2021 20:24:58 +0000 (UTC) X-FDA: 78188139876.03.99C98E4 Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) by imf23.hostedemail.com (Postfix) with ESMTP id 78361A0001E2 for ; Thu, 27 May 2021 20:24:51 +0000 (UTC) Received: by mail-io1-f49.google.com with SMTP id a8so1823852ioa.12 for ; Thu, 27 May 2021 13:24:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=c5avyG+JG+HCBZSkDHForBT/c7WMYaoLNLCgHmVeHfQ=; b=tGLmVooHuS2o17KbfETPft8otJ7SRvE8WXwimHMaLvVxp6MqNU2wheCQ83mQUuovo1 YCHzuRv1MiQo2QJhNXkeFtPR+0D6ClRNkILmmf1uXPGj9IEfgXm0EPxOpm40iYsmW5Sg BQRlOKtj59cy35CccHVchDqh5FZEJ87FQ1Icopd73tXEbMJ7T+fYrJbtcro4GOhdtfr2 Wdmv30kJ/lZHb2dnAIq7Zb8zILMBRMdSgNf4C8TB0eMJZpHNcw2qdjjYGB5YZ/4e9MZp pF9ldMiHSRuPGzxym3uo8zwu7KiYErta+7dzp3dYeY75D9t5mFc8ZW1U8YEZ/9nrjrCN UeBw== X-Gm-Message-State: AOAM530gF4TIURRK8dRInJPShcgmLlNrC3TOfa7joriallKzgmFM4+Rh mzWs8DRZLe5NFkv00+H2E2U= X-Google-Smtp-Source: ABdhPJxuqBvZJLjl7cqOx+pzzc28YudKBtnl2uT3U+QHzhvlP9kfRDVM+jRRpZQEE83MxpnWGvyWcQ== X-Received: by 2002:a02:908a:: with SMTP id x10mr5067710jaf.30.1622147097974; Thu, 27 May 2021 13:24:57 -0700 (PDT) Received: from google.com (243.199.238.35.bc.googleusercontent.com. [35.238.199.243]) by smtp.gmail.com with ESMTPSA id o18sm1690240ilq.9.2021.05.27.13.24.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 13:24:57 -0700 (PDT) Date: Thu, 27 May 2021 20:24:56 +0000 From: Dennis Zhou To: Tom Rix Cc: tj@kernel.org, cl@linux.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] percpu: initialize best_upa variable Message-ID: References: <20210515180817.1751084-1-trix@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf23.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.166.49 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 78361A0001E2 X-Stat-Signature: c1fsfyndh7qhbfhqhjmbewwrr3wne81e X-HE-Tag: 1622147091-826854 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: Hello, On Mon, May 17, 2021 at 02:39:21PM +0000, Dennis Zhou wrote: > On Mon, May 17, 2021 at 06:17:47AM -0700, Tom Rix wrote: > > > > On 5/16/21 7:05 PM, Dennis Zhou wrote: > > > Hello, > > > > > > On Sat, May 15, 2021 at 11:08:17AM -0700, trix@redhat.com wrote: > > > > From: Tom Rix > > > > > > > > Static analysis reports this problem > > > > percpu.c:2945:6: warning: Assigned value is garbage or undefined > > > > upa = best_upa; > > > > ^ ~~~~~~~~ > > > > best_upa may not be set, so initialize it. > > > > > > > > Signed-off-by: Tom Rix > > > > --- > > > > mm/percpu.c | 1 + > > > > 1 file changed, 1 insertion(+) > > > > > > > > diff --git a/mm/percpu.c b/mm/percpu.c > > > > index a257c3efdf18b..6578b706fae81 100644 > > > > --- a/mm/percpu.c > > > > +++ b/mm/percpu.c > > > > @@ -2916,6 +2916,7 @@ static struct pcpu_alloc_info * __init __flatten pcpu_build_alloc_info( > > > > * Related to atom_size, which could be much larger than the unit_size. > > > > */ > > > > last_allocs = INT_MAX; > > > > + best_upa = max_upa; > > > > for (upa = max_upa; upa; upa--) { > > > > int allocs = 0, wasted = 0; > > > > -- > > > > 2.26.3 > > > > > > > I think the proper fix would be: > > > > > > best_upa = 0; > > > > I was looking for initializing with something that would work. > > > > I think I prefer setting it to 0 because it forces the loop to have > succeeded vs being able to bypass it if the for loop logic was changed. > > > > for (...) { } > > > BUG_ON(!best_upa); > > WARN_ON instead? > > This is initialization code. So if upa == 0, it really is a problem. > Having 0 units per allocation is bogus. > > > > upa = best_upa; > > > > > > If you're fine with this I'll make the changes and apply it to > > > for-5.13-fixes. > > > > > > Can you also tell me what static analysis tool produced this? I'm just a > > > little curious because this code hasn't changed in several years so I'd > > > have expected some static analyzer to have caught this by now. > > > > Clang 10 > > > > Tom > > > > Thanks, > Dennis Following up here. Are you find with me making the changes and attributing it to you? Otherwise I can just spin another patch real quick. At this point I've already sent my PR for-5.13-fixes. So I'll queue some fix for-5.14. Thanks, Dennis