Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp447172pxb; Thu, 9 Sep 2021 04:48:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTECBiOawG6awCoLq9RWhHSor1TKHEaHqRbnwafEn7zUR1lD+x1WPftoU9H3bGSdF92/NX X-Received: by 2002:a02:b0d1:: with SMTP id w17mr2456285jah.46.1631188130250; Thu, 09 Sep 2021 04:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631188130; cv=none; d=google.com; s=arc-20160816; b=oOoEzkEHGRLGBSqp2UjmEkPDwCEfgYkivECIkQH/XSomDh/Gw44i7iBFNJae0ACPqq I9LzPhBoPcsboVie7ytQvyfiMiElAROKveriv/c36LDMjdsVRIQZVleMhh9YldJtSHE1 /Ocw732kaNnbem6ZsiCj31CscdQO7SDxDBkVBGGjUoB/Y2Nq10s0NpAFuT3ebVwpuePM fWL0iiPcFl5XWnvfe84Hft+tPzowUgpkkKjCaoXinhL5zNUUqEeMM10cfhKmii5TsBj9 HhNDswRPFYa/0kJihQta5d8xW1cGDeJPICUllDq2nwuynPUGg3hY53S8z3M6VxX70lJh Nemw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LxoyaFE2+mFBnL0wUnCf5+HJdTpsBXFSHiwHeu/+zqc=; b=vILYsDr5MvLfDEFqfQ8CSShaofkk0WL93yEFxBx7NlX9eWlaIsiglcd+mgtmJWubVw G2clVmZfjD0zTUF1gPTMn5oo56QTTeTMeSs+OHsg0J044pZCppw7yliDlAMxR5AvQmUu dBeVnApNey3C3sHKbKpmsRUukcSK8HRbhkyDRGm0Hu2wrSHKKSemXwMuJu0QaOv5l2ed dnKVgUBp7FDkziIgWbln1U2uzIHortAoXDwFK3mX6x4nWM9Eqzuk3pxTUBcKxHXKPLEa aqUMXPj+W1zuNXSk21rvMQ61ajHetojr+7Wef0aYQujyE55UwwZAyqL+Ae/HgcllYDFu OqcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XosYVSl7; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m82si1294287ioa.74.2021.09.09.04.48.37; Thu, 09 Sep 2021 04:48:50 -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=@kernel.org header.s=k20201202 header.b=XosYVSl7; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240266AbhIILtB (ORCPT + 99 others); Thu, 9 Sep 2021 07:49:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:45698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240250AbhIILqr (ORCPT ); Thu, 9 Sep 2021 07:46:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D5C3E61251; Thu, 9 Sep 2021 11:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187782; bh=oltsHO7IqEbcDmVpHsfYgiUzO55j3987ysuyH8GOkfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XosYVSl7XzQ4H2cciFeCSCOuLMyHdbEbyohNVR3x8H7Jx7xdWQJMfsFgPYUa7ZBR1 mgBN3L/uhC5D8DH9COn8Xa7BocF/fPMGFGCy+56WNGRYs6OwpGJgv5EYKk4AYl3MOY LZeYDipg7BeU09y0YLBfXLGxYUcBUzbh7zrS32af6/beYN1ZKiJAagbkwoMjKxNvrz MVrhMHj7KdzMRdXL25OYCKVc0p5phvhS3E6ybMu7CWuXZ5PrqDRBXG01GfnYIvGkVS fZk6mcI2RHNbjflKSfRueqPSCHRJI6v3LoCP5cMZqjQtrjwCGEsDO9+owchje0nlts 7ox8yssBJK5UA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhen Lei , Lai Jiangshan , Tejun Heo , Sasha Levin Subject: [PATCH AUTOSEL 5.14 091/252] workqueue: Fix possible memory leaks in wq_numa_init() Date: Thu, 9 Sep 2021 07:38:25 -0400 Message-Id: <20210909114106.141462-91-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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