Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1928754pxb; Thu, 16 Sep 2021 20:36:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytGiLvvFf8pLoHIPyuYjGVMFRd4iQ8dqqOI+BLoH+CKhKS0WjUNY1CJ8x6QOk+AiW8HzWs X-Received: by 2002:a05:6402:7d6:: with SMTP id u22mr10266485edy.156.1631849775563; Thu, 16 Sep 2021 20:36:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631849775; cv=none; d=google.com; s=arc-20160816; b=v2MSL9X6wrH9p3BLyO9kxsqUGsfMV8QLWsfhYJ9IHjgtg9rXypjSwAt179EUHv9hf8 yIaxRS3BuUFtLpwwoemwTtIgNbn8B/xf+BR+qIJXRi6tzDvRtZp4BJUJNLgqH5l+MwRG E5Ki8a2410Ybrl/Az41Xht3KtBs+p9U/UVZVc4SNy0qrO06h+xbeuIhYmBl4+m2X+8SY nw6bO1CLxuAX2b2LSbaTqRDQfd/hRTb4QNJ2SAiXusagn3bPebWnuMbgeAJiBCRops95 yTmu9gb3MkjPaAnhUm1XblF4k1OzSttDSisUEmymWX9sVm6cmt9ZTuIjGf9M35E3lR6P Y2Mg== 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=tnX7++l34UlyANOKAgzPDkh1uYMcGntalKulUAj2ZFkRIkILshjS1IBBI1wYMh+ZF1 +JmxBy5VGAB7F/pjDGsSb931uO0MZ/bw+9IfT3SkkmZJ2s80FwJAO4OvMEAHmeiv2CTc YTBYlGCJBr8fb/yF5jdViCeO8OlLGvMXlAC3Pd0LaVUqkX64x8wgGLU5Ad99TZAWyPcK A1tYd8fOPlGN6kh1wt4K491dmokbsPvT+RkIFycFmIxXJQ8a+28RkDwrrAv3Ggo+MvtX QyilKj8Jx67hnhDa00dcdywUKaWTdbobzAH2SGQIXoayKSeRqzJ40OfRWmRe00wozZEF jHUg== 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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 z15si6417613ejr.28.2021.09.16.20.35.51; Thu, 16 Sep 2021 20:36:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S1348359AbhIPRg3 (ORCPT + 99 others); Thu, 16 Sep 2021 13:36:29 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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]); } -- 2.30.2