From patchwork Thu Sep 16 15:59:51 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: 513030 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1432169jao; Thu, 16 Sep 2021 10:29:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOcuieamyHT1WeWDuEcisIZhR30jYVwaKC9VVFQI11aqWrJYyirsN5Z3Yehq92JyspMq7j X-Received: by 2002:a17:906:cc57:: with SMTP id mm23mr7556528ejb.540.1631813386157; Thu, 16 Sep 2021 10:29:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631813386; cv=none; d=google.com; s=arc-20160816; b=u9/8rKDgglQgvxGhsVY+SZuWdeDV7GYUtYH5u/Fi7SO9MXQ8wjL5sV/o7bW/nVhoA4 kW5xvZCjZcrCU7zaebNT46dgnz+btsUFsyQbZLPDUY7puVG0M/ozI0G+OEkFGDMZAIta 82rd1M5ANTBobBZU7o2e0hsB2QCmD6xTBZujmv2W7rF4gGetuXbGlhfLQPoQFhlDmS5N COTKKDnYNdqU7Mz6cQToHcEtggxQ6895kR34zq7LLI4MfmKisfkN/HNPbdTafyXOeuuO Kfi0BHVWfDMqrIjcNsOElL5/d7k5YueAHdwGG9pDtJ66f85omkI2L2YPp9At7ivMbrY8 Qa9g== 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=aFRw0yquBK3FOGxAsJ4fH8EWa7ZKYoRHjxFSVPAXJ/pk6dwvzWDS2JSAkZjhMSIld8 SHgguIKW27RmXIMyO5dSJzjfJF9JclnPx1bGOInP8k/EMD/NteLy+RppMEHkH+o5plBS 1Ifoxur0tShPoOfHigP37tlZSumRwLu6OkoNTi5cRz7lTpw4K3qc/P3SQuIQpXlmlppB jmcoT+NuNBp042cMIpIvem/PWY9qffW2fKIzZrt5L5eP3k83DQhrLjizx3n0dreMGoSk /nUbw77jV6iwiO9AsV7fa1CnBNqCqMKDoGR6CfqccV2WeXfa/YhdIlT8exqBc8P2f8S8 OQ1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PJUO41Z8; 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 bu15si4061325ejb.164.2021.09.16.10.29.45; Thu, 16 Sep 2021 10:29:46 -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=PJUO41Z8; 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 S243537AbhIPRa7 (ORCPT + 11 others); Thu, 16 Sep 2021 13:30:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:46958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348929AbhIPR1v (ORCPT ); Thu, 16 Sep 2021 13:27:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 475B861A50; Thu, 16 Sep 2021 16:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810715; bh=oltsHO7IqEbcDmVpHsfYgiUzO55j3987ysuyH8GOkfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PJUO41Z8tQlc35V5oAD39yxH5ggNARhE4nWaq8Wn25Mc6AkSKvBUJ9ZHJyuVeR9lU gYpY2vlXXDfurZTcmaNkHzGDejjxvRm8APXZ3QeM0Okf/pF11ZqpxpvDC3AYNE6qHG JiKuQeP8ZD0+n/+nH4wZBqDW/O3ijx1dj0kbMQn4= 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.14 242/432] workqueue: Fix possible memory leaks in wq_numa_init() Date: Thu, 16 Sep 2021 17:59:51 +0200 Message-Id: <20210916155819.033271084@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@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]); }