Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4889736pjb; Mon, 27 Jul 2020 07:41:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnpM8Xq4hfy41d7pvRZQ3HMsa9QRvKR9HmJQI/Yx/wdvNzLjpEUDP6YAtz8jD+jLlD7/h5 X-Received: by 2002:a17:906:26c7:: with SMTP id u7mr20594010ejc.13.1595860883378; Mon, 27 Jul 2020 07:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860883; cv=none; d=google.com; s=arc-20160816; b=zI5y+88xUA+J/wt00aHvBqw96NBTfcK1PjlaM9yBXcWVFqK5TsmvHv/muC2Yp4/Www RO0voJmlIn3ZDScVY/NDe07N3Ng2viPjfxYOTrxo5QIV0uTImXpDtl0UWtA0SRJXtx+j EuLYaM6yzf+OVsxYpKqps/crdyg369G1cjNPo8PYYOmvmB5h383UKeWvd1kXZEUEwd6B K7U495tQb2k/YQtE2gKLNFDKEZxxZRSebUdDAEZWJF5NLPr9HmfUuIOdZqIlQ0m300Bl Yta8v2EeMLpRqpYvcr54Vw3Zws0LhW9QOps5CGM3ejy4N+J5U/v++0tBQ7Q1pHocZ4rX 77WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HElfJFPOVyC0Xu7X+uDsi5fEpvzerJp6ATUwLl6cJ7M=; b=HIb3fTx8PHX3X7jEgdCs3d+CMQIw/dkBxhyEaUdoHOnyolb97Ywicv4qJ3pJDmIzOk bZHrjc5kXIxzSAWxaMaadXUT/YVjGgOboPW0vgwuRhWPTD0xX+b9Q2eReTZ7ghndxCYq aAu5F4zzlAljFnKNYMREWcUcnI+g0GQVrzSFbKGVTDBsIjIXzFyvjKrHxlSTL3qd3RC1 +3CXoDCQp4USONIxZa6B6Q6W6KTMhqtM8xc74VIuDcIG0ic3fCR2b+vTqEQhK5hf95hH jlGPppFTXZ9ZLlarZVSt+ye5oX/nWD8xBD5mgsh5aZtBdIdPbBpZmdNGVL7zF+4mNBPn 1RVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VxOZNnTy; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si3092565edu.590.2020.07.27.07.41.01; Mon, 27 Jul 2020 07:41:23 -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=default header.b=VxOZNnTy; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729625AbgG0OJU (ORCPT + 99 others); Mon, 27 Jul 2020 10:09:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:59302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729618AbgG0OJT (ORCPT ); Mon, 27 Jul 2020 10:09:19 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 120F8207FC; Mon, 27 Jul 2020 14:09:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595858958; bh=6BIAxrKabhOJYy2xeoMCfBD72A96CeHELJj9q3yhH6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VxOZNnTy3lpLjc5ELy2/V9yldu3YO1uAHC9j+bpAcx/uu0DZYCk6sxx640lIER/Tl BAUGZ6HiWMP/pqNqY3ZAtKqSXBGqWfAd1pVJ6n5GUK21fj0ypB4s1uUIjAX7hnxRPO DRZwTs9WnLwm7L24LeXGZCvs45yrCmH1rD0zYwKA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gavin Shan , Sudeep Holla , Will Deacon , Sasha Levin Subject: [PATCH 4.19 12/86] drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups() Date: Mon, 27 Jul 2020 16:03:46 +0200 Message-Id: <20200727134914.952600087@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134914.312934924@linuxfoundation.org> References: <20200727134914.312934924@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gavin Shan [ Upstream commit c377e67c6271954969384f9be1b1b71de13eba30 ] The CPU mask (@tmp) should be released on failing to allocate @cpu_groups or any of its elements. Otherwise, it leads to memory leakage because the CPU mask variable is dynamically allocated when CONFIG_CPUMASK_OFFSTACK is enabled. Signed-off-by: Gavin Shan Reviewed-by: Sudeep Holla Link: https://lore.kernel.org/r/20200630075227.199624-1-gshan@redhat.com Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/firmware/psci_checker.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/psci_checker.c b/drivers/firmware/psci_checker.c index cbd53cb1b2d47..9f1a913933d53 100644 --- a/drivers/firmware/psci_checker.c +++ b/drivers/firmware/psci_checker.c @@ -164,8 +164,10 @@ static int alloc_init_cpu_groups(cpumask_var_t **pcpu_groups) cpu_groups = kcalloc(nb_available_cpus, sizeof(cpu_groups), GFP_KERNEL); - if (!cpu_groups) + if (!cpu_groups) { + free_cpumask_var(tmp); return -ENOMEM; + } cpumask_copy(tmp, cpu_online_mask); @@ -174,6 +176,7 @@ static int alloc_init_cpu_groups(cpumask_var_t **pcpu_groups) topology_core_cpumask(cpumask_any(tmp)); if (!alloc_cpumask_var(&cpu_groups[num_groups], GFP_KERNEL)) { + free_cpumask_var(tmp); free_cpu_groups(num_groups, &cpu_groups); return -ENOMEM; } -- 2.25.1