From patchwork Thu Sep 16 15:59:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 513007 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1396519jao; Thu, 16 Sep 2021 09:51:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9LRmO0yQNO/ERu+Qg1GI/AmvLEhgrzFC7X/CnLdvfb5J8q79pVrQN0JrjU4NT1UBS4SXs X-Received: by 2002:a17:906:c1d0:: with SMTP id bw16mr7568537ejb.146.1631811082489; Thu, 16 Sep 2021 09:51:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631811082; cv=none; d=google.com; s=arc-20160816; b=jvZZRE0tWJ3ZE8Of00yBDzUdMvEvrXPeEJzAZ3J+thcnJJL3Bv7+p8w5MzhDfF7p9i hwZhuoSdDjizai9w7f7XwiWEQwE6IoobcNS6jJjXXM2bGFaoD0h8OVLwJGtORall8jcg a7M3YFdmRK+B+FgRVpsvIHiAAG9s9lWWFbZPw7dX4hVb8nLrrSjTa+ATWrLw4zvF67UU Ty0MoQgCGYyJjRjH95imKVZy6kQMT39dYnyF0A9FMi+Lf36uYRKLrqILGEa/i3XbU2Z9 DU23oV7PjqqyT56L4/+9+vuJpkM0IcC2ZSI0eEWv5z9nH3SZ1s62rWt7vkxQi0iU5XIM NkaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LxoyaFE2+mFBnL0wUnCf5+HJdTpsBXFSHiwHeu/+zqc=; b=gz/nVnKQ8XxQ2TlTXKKeUXHIto9Nc/WgasqA1Q5Xp0sN9y2PMaCtW5qw8safvq2uFG OZlWTDa+KGCCibFsD1gr5chlw2uzO5kRvwU2+MT6QqLGoF62BGYzgxeX7t7W6cmPJDjL KkUEDXVrAIUJQCmgo0p651aOGqpNEH7CwtoWR7/2MycEETqln0be8Xh0Ku1gWWi1ogLz kt0ahZ+tXE512R/I6DOHEhUdOI99hN2PpWLA/PG+NRLJc0cdfm5vQRHPNYT/b9KmxbpR YynJvc5B15uX5RfxttxcKiWF8X4X/KVG+r05+eDLqaLxXQg2SU0cAEKq1CceLfve/+MF rJFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IOvCOJEp; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e10si5341164edj.183.2021.09.16.09.51.22; Thu, 16 Sep 2021 09:51:22 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IOvCOJEp; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343793AbhIPQwl (ORCPT + 11 others); Thu, 16 Sep 2021 12:52:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:40196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345309AbhIPQuF (ORCPT ); Thu, 16 Sep 2021 12:50:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 38D9D61555; Thu, 16 Sep 2021 16:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809685; bh=oltsHO7IqEbcDmVpHsfYgiUzO55j3987ysuyH8GOkfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IOvCOJEpDdUAQkZdSh8Sqsmi26WFCPDSPZKdGUlc0xvwbmxgASHmv3NNbLTAg8q61 JI/qYSt6iYdjEkihyzSaAY01w8/nB+Nz4z34tTWztT9sH5AJJA/uG6643aqzJElrbr 6GzvflA6RPRuEnIQ2v8SeE2cZC4QucNavxn7Oglw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhen Lei , Lai Jiangshan , Tejun Heo , Sasha Levin Subject: [PATCH 5.13 213/380] workqueue: Fix possible memory leaks in wq_numa_init() Date: Thu, 16 Sep 2021 17:59:30 +0200 Message-Id: <20210916155811.323182598@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Zhen Lei [ Upstream commit f728c4a9e8405caae69d4bc1232c54ff57b5d20f ] In error handling branch "if (WARN_ON(node == NUMA_NO_NODE))", the previously allocated memories are not released. Doing this before allocating memory eliminates memory leaks. tj: Note that the condition only occurs when the arch code is pretty broken and the WARN_ON might as well be BUG_ON(). Signed-off-by: Zhen Lei Reviewed-by: Lai Jiangshan Signed-off-by: Tejun Heo Signed-off-by: Sasha Levin --- kernel/workqueue.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) -- 2.30.2 diff --git a/kernel/workqueue.c b/kernel/workqueue.c index f148eacda55a..542c2d03dab6 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5902,6 +5902,13 @@ static void __init wq_numa_init(void) return; } + for_each_possible_cpu(cpu) { + if (WARN_ON(cpu_to_node(cpu) == NUMA_NO_NODE)) { + pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu); + return; + } + } + wq_update_unbound_numa_attrs_buf = alloc_workqueue_attrs(); BUG_ON(!wq_update_unbound_numa_attrs_buf); @@ -5919,11 +5926,6 @@ static void __init wq_numa_init(void) for_each_possible_cpu(cpu) { node = cpu_to_node(cpu); - if (WARN_ON(node == NUMA_NO_NODE)) { - pr_warn("workqueue: NUMA node mapping not available for cpu%d, disabling NUMA support\n", cpu); - /* happens iff arch is bonkers, let's just proceed */ - return; - } cpumask_set_cpu(cpu, tbl[node]); }