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=-17.6 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,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 2DD51C47089 for ; Thu, 27 May 2021 21:09:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 966F2613E6 for ; Thu, 27 May 2021 21:09:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 966F2613E6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2CC546B006C; Thu, 27 May 2021 17:09:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 27B266B006E; Thu, 27 May 2021 17:09:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CE196B0070; Thu, 27 May 2021 17:09:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id CAB446B006C for ; Thu, 27 May 2021 17:09:49 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5BCC1181AEF15 for ; Thu, 27 May 2021 21:09:49 +0000 (UTC) X-FDA: 78188252898.27.E7CE793 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 18D622000BC4 for ; Thu, 27 May 2021 21:09:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622149788; 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: in-reply-to:in-reply-to:references:references; bh=yYCU0AwNZCgbe0HM2uiCGrbOSvKYgrER6VSFwgOWNSg=; b=VbmWc7tB1hoQQmz3pYC6PfIeNcJpmi0SQumpwHCsbRgEjyv4K5xjVJN2H0Raoiybj4QIrC 9hnZkB9oewfCd1ph4fCmZfo1v1jv6iXDk/P0aK9UnufDNbmtUPr/dQZBrMRJgj1WEckxXE 5kCYxDUQDSSk/KlJ0a90PEiDC7Hi2O8= Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-182-5I24WBm5MLCkNGpe2l4QZA-1; Thu, 27 May 2021 17:09:46 -0400 X-MC-Unique: 5I24WBm5MLCkNGpe2l4QZA-1 Received: by mail-oo1-f69.google.com with SMTP id o21-20020a4ae5950000b0290211a73e7f50so982556oov.12 for ; Thu, 27 May 2021 14:09:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=yYCU0AwNZCgbe0HM2uiCGrbOSvKYgrER6VSFwgOWNSg=; b=rmlgfYOzyD0H7kNF+MgnNMcjsOplMmBhBs7XR8Igbdsto2FWHgCFA0wRLXd0jLJEYQ 278JOXPt2aK8ErCj2mUlSxHbAEwPNUaJQCtJLC9i4CQpIOSwd0CTLluueSoyNl+k2s4k ASs6oD8Pt9hB5RRSu7LQ3f3zDklDuB0HsRxOCUHdlQE9OEZIcUJCzZ+Ni/6nrj57HwOt 9/JHiMnqjv1TRNtkD6SiO2Ss42k34i7EzHHrohjfs4Bk6vqnY5GcJcAuzBLSUFg7ZFVR cxLcTf0GguYjyuMVyqOzl03GydLlj54X3krFk+xQ9Zw7NbyqH63srscu6DJul9dUA77T hR5Q== X-Gm-Message-State: AOAM530fq01OozsBS8oKy0gLJbC7t7RgKrrO9FORmM4Kf5dbD5eryMB6 5JWfhR8xOQjR+tzlDBZP4zBUqGdM1mvxudm/3P42GNa94at0y0hmviFmjodXRAFqdMgGMhsajHn NwI2aMf0YmiA= X-Received: by 2002:a9d:6444:: with SMTP id m4mr4440106otl.124.1622149786053; Thu, 27 May 2021 14:09:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeLoT6fSUCKNnag5ungWi0Ue0kKJfTQKBZusMiWBPiOTPaWlnxkjPVrF+veyO7F9+IgRIaTA== X-Received: by 2002:a9d:6444:: with SMTP id m4mr4440087otl.124.1622149785842; Thu, 27 May 2021 14:09:45 -0700 (PDT) Received: from localhost.localdomain (075-142-250-213.res.spectrum.com. [75.142.250.213]) by smtp.gmail.com with ESMTPSA id r83sm686643oih.48.2021.05.27.14.09.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 May 2021 14:09:45 -0700 (PDT) Subject: Re: [PATCH] percpu: initialize best_upa variable To: Dennis Zhou Cc: tj@kernel.org, cl@linux.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20210515180817.1751084-1-trix@redhat.com> From: Tom Rix Message-ID: Date: Thu, 27 May 2021 14:09:43 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Rspamd-Queue-Id: 18D622000BC4 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VbmWc7tB; spf=none (imf28.hostedemail.com: domain of trix@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=trix@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam04 X-Stat-Signature: rndbx1gaz3e5wuuokb753dps37kg5356 X-HE-Tag: 1622149780-664096 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: On 5/27/21 1:24 PM, Dennis Zhou wrote: > 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. I am fine with you respinning, no need to attribute the change to me. If you would like a review, include me on the cc. Thanks! Tom > At this point I've already sent my PR for-5.13-fixes. So I'll queue some > fix for-5.14. > > Thanks, > Dennis >