Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2339840pxb; Mon, 20 Sep 2021 19:22:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvZZioleM60xGBpAPraXqzZK88hLPlDNC33eZfyKsz33H/RmSl/qkOClNYVIQEICXYyGne X-Received: by 2002:a17:906:64dd:: with SMTP id p29mr32710462ejn.255.1632190974305; Mon, 20 Sep 2021 19:22:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632190974; cv=none; d=google.com; s=arc-20160816; b=X1XDy8hGTMVS1ad2BkGqrHceYj3RgHf1U6eoALrNyXi+/6ZjtFky2WLUf67FkypJMQ xPTd89PqrS4IxcdNP7PK5pNlMZorL4AJ2v6j+hopu9ZwfXmjc5F0tQN8wXZkdtfQHI9T qms88ApIS3fRZkMiW8MivhHrmuC/B4F9YqPbjCk6D35Y8MhBp41q3DSZRGOVhCLsYg94 VQKgl+HcxeTwEuH0SOvJsMew/Uai0GtFgWl9Y5hcS5GEzllhYChj1gq6OhEaoM+JHWs8 81QiEEcPFPTygA/l7i9eQPTLbilyuSdXDKOT7g+mlxina1OslsjRi6PeklgiHcSZW+Ms ZVxw== 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=nLrhV6bXMF0sLDO6zIEcp08uEvz7NAowsEAC9IOX69Q=; b=RcKAvYTueC1fvugbBbbeOfd6dr0l+bD+EJcrP65vLn1qj8dYdrHckrjQ1zNduUzAih K7aEat2fJcDqzMgpH9FvVuI9JQRaFdQelbmCjQbO5siZ3qPN507hjowzjO8AMjn8GsSd TVVe4k8SYRMztr5jJlT0heP4v0D9vX369tKEV5B8vBUiap4vi25mQdPbcgI0bYEGasrK rJhx8pEKHpUS7QCo83kC3EW3yfpXzG69NBrlWXCOXkRy4Za8jXN0e+cLPU1WTPEitWID g/6GegNO6RTheWZ02ykkG43NkiHEnymdErsWMpg+d/W9cMdJvPfg9+2Iap7jrvxAD8WL co8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="a/89sdiu"; 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 s1si19507430ejn.348.2021.09.20.19.22.29; Mon, 20 Sep 2021 19:22:54 -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="a/89sdiu"; 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 S1376567AbhITSNI (ORCPT + 99 others); Mon, 20 Sep 2021 14:13:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:35750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359124AbhITSJQ (ORCPT ); Mon, 20 Sep 2021 14:09:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1AC0061A2F; Mon, 20 Sep 2021 17:19:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158347; bh=Xlm9vH/YjbETQX8HEjiDtLEamI5UM7yyDWivHSRuFoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a/89sdiu/z2LbtZ4uLbUgLpM4XfdtMzjbM4uagaYf85HLohZXTKCoJlvR26xj+vd2 hccJbCkHuQlycC3/t7kKLAyPBpiTnwDZ98d3ne3kSz818NeuCS1loGlBUz3HfgTdWt c/t7oUm6b4AeyHWpT5Zf1vKw+vzCwenlwhnHEUtc= 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.4 113/260] workqueue: Fix possible memory leaks in wq_numa_init() Date: Mon, 20 Sep 2021 18:42:11 +0200 Message-Id: <20210920163934.980383338@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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 6aeb53b4e19f..885d4792abdf 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5869,6 +5869,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); @@ -5886,11 +5893,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