From patchwork Mon Jun 14 14:50:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Zhou X-Patchwork-Id: 12319075 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.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 53C79C2B9F4 for ; Mon, 14 Jun 2021 14:51:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AC3056128C for ; Mon, 14 Jun 2021 14:51:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC3056128C 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 0EAED6B006C; Mon, 14 Jun 2021 10:51:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09B536B006E; Mon, 14 Jun 2021 10:51:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA4B76B0070; Mon, 14 Jun 2021 10:50:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0061.hostedemail.com [216.40.44.61]) by kanga.kvack.org (Postfix) with ESMTP id B73146B006C for ; Mon, 14 Jun 2021 10:50:59 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4ECB78249980 for ; Mon, 14 Jun 2021 14:50:59 +0000 (UTC) X-FDA: 78252616638.27.3BDDDAD Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) by imf13.hostedemail.com (Postfix) with ESMTP id E6014E000271 for ; Mon, 14 Jun 2021 14:50:50 +0000 (UTC) Received: by mail-il1-f170.google.com with SMTP id z1so12486276ils.0 for ; Mon, 14 Jun 2021 07:50: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:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Pni7rpqE1FW1FClvYjK9AqvghJIehVdwsak3wJBmgPw=; b=FrOCmrWuAXZ+u22N+S37dunnZI+rk05O2jqUTSypgioZto6zaPYevTXx++QOzWtYCa QLMde0vnPoib29NrfFZIrn6VcI6ZzvDA7FaUTNwP9UKHG/5BxmaywPb52N/+cqYmjDRs zqMDWaczlMW+wXjHTrFnTl49xJrHq+V5BQHNuPVPv3zEQGjtZJykGaLdb5YSJO4mk/92 KoKfbYedckSgGQ9tuMkSjtL/UVrWP2Jm+wB+iVHmPe5hWe2ZAaPqpfqkY9u412U5UvSf XAUMsZC1FF9biWfA5d/LiF6oA/p9AOxiRFqHt41z+jm3B6Ti0tortxnE1vLqiHS/uCg6 CMDw== X-Gm-Message-State: AOAM530jWY5oow9LNpkpOFGby6FurjFlx+XYYvBe6RpF/bOaTBa+LHKt RNljEARj6J/222ciYm1zYR8= X-Google-Smtp-Source: ABdhPJyYTZCCa5KdLDhWat+CcyfLYG0jp/N4a8MKcpG+27+jQXlzKazy+lyYCyayxvxQWQDNQhFdqg== X-Received: by 2002:a05:6e02:cc5:: with SMTP id c5mr14366617ilj.152.1623682258502; Mon, 14 Jun 2021 07:50:58 -0700 (PDT) Received: from abasin.c.googlers.com.com (243.199.238.35.bc.googleusercontent.com. [35.238.199.243]) by smtp.gmail.com with ESMTPSA id u18sm8350925ilb.51.2021.06.14.07.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 07:50:57 -0700 (PDT) From: Dennis Zhou To: Tejun Heo , Christoph Lameter Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dennis Zhou , Tom Rix Subject: [PATCH 1/1] percpu: initialize best_upa variable Date: Mon, 14 Jun 2021 14:50:49 +0000 Message-Id: <20210614145049.1585477-1-dennis@kernel.org> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog MIME-Version: 1.0 Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.166.170 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none) X-Stat-Signature: xub3zqh7tpj8mwxttt353qznmomgkbxk X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E6014E000271 X-HE-Tag: 1623682250-450854 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: Tom reported this finding from clang 10's static analysis [1]. Due to the way the code is written, it will always see a successful loop iteration. Instead of setting an initial value, check that it was set instead with BUG_ON() because 0 units per allocation is bogus. [1] https://lore.kernel.org/lkml/20210515180817.1751084-1-trix@redhat.com/ Reported-by: Tom Rix Signed-off-by: Dennis Zhou --- Sorry this hasn't been my highest priority. I'll apply this shortly to for-5.14. mm/percpu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/percpu.c b/mm/percpu.c index e7b9ca82e9aa..6667dfa0fcec 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -2888,6 +2888,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 = 0; for (upa = max_upa; upa; upa--) { int allocs = 0, wasted = 0; @@ -2914,6 +2915,7 @@ static struct pcpu_alloc_info * __init __flatten pcpu_build_alloc_info( last_allocs = allocs; best_upa = upa; } + BUG_ON(!best_upa); upa = best_upa; /* allocate and fill alloc_info */