Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4877038pjb; Mon, 27 Jul 2020 07:24:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzWHArsDdbzWpLswSCCMxClpbrpKOOwxg3LiM5kvnJGl9ilx1FR7NjRFUsve5XZaYThGIq X-Received: by 2002:aa7:cd07:: with SMTP id b7mr1425045edw.172.1595859848296; Mon, 27 Jul 2020 07:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595859848; cv=none; d=google.com; s=arc-20160816; b=pjcTsLG43LZK6AAM+kr3MthjnEIx0ihz5oLDeKOuCVYfaPxON4n7/I/hFsCtJItSgs 3Kg84AjFzm/XEIwC/+lHdDGOMqd/h323QW+J6aBRk8O7n4P4e3ailSUhLFDfKk077TcD t13lT0OQ9V9gASelidSkdXynJqMvfKnSgfKEvkitMMPuPtRcmHfXN0Hpa9XGgQod426X 6ufg9bwHeToMGCIYu1NSEIHyQchOV15dk7xDUTVFiRbUabP0sz74lxjYEwoEy1LGwrmV WEaM3YOGwa6ypSzePPdCRk7Got3x+aMpM5NPvymwRLz8nYO1kpdo369WcicT/9SIS72L xopg== 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=+cxzOr0wczTGUsOR4LZPR6BdPk1iwUdmHe1sxEYJtdg=; b=q1I7ZyVClAgYeUgSS/fq+EkCqmzXrYR7wRQPnIVaF6A9FHeHlJMvyqaxbHTeZmPecO 00qbpAc0pfi+tH0ym8+tsfrJP1l+XnDKHAxyiA67AffE9TRoAOmyqkiMb9O+hv6fc/WC jP/x431kh995LZw6malyUY0hbHh7id8UOv8yEsIRYmsMvSjcRDgKnu04BTKwXddZgDMY GFu/Q28d/rJkOVLbxzBlef5deeKki9gMSNFh6gjuYxgeNMm/TzzZ8dEVdB+A2J207e6K WIr1YY1MoGe7d8BkcjMNaCQos6S5ADH9ELBmRK1gVqYTks/ye4KS8GBLscy5nqFn1cxH w+0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=If0ytJMY; 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 k24si5632148eds.441.2020.07.27.07.23.45; Mon, 27 Jul 2020 07:24:08 -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=If0ytJMY; 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 S1731507AbgG0OUJ (ORCPT + 99 others); Mon, 27 Jul 2020 10:20:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:48232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731495AbgG0OUF (ORCPT ); Mon, 27 Jul 2020 10:20:05 -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 A7EEA2070A; Mon, 27 Jul 2020 14:20:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859605; bh=6ycqmBgJjHjv734+lHtackk/20kto5gQnyNFO9LxvNQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=If0ytJMYjl341C6txuL0/bmCNnfBLJd6BPR31Sh5cqiZt67rvdAyUbr/tcrflwEqN nZCXFnIKoynoJk7GgN1q5Z0vEsf0dWGmIMDt4LHiNRrfcf7gPuDRNhznoCMxShLzoK +Y274IikiD1aFeRIwDRmzApvACHZvTuxsh6kQhVM= 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 5.7 018/179] drivers/firmware/psci: Fix memory leakage in alloc_init_cpu_groups() Date: Mon, 27 Jul 2020 16:03:13 +0200 Message-Id: <20200727134933.558050600@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@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/psci_checker.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/psci/psci_checker.c b/drivers/firmware/psci/psci_checker.c index 873841af8d575..d9b1a2d71223e 100644 --- a/drivers/firmware/psci/psci_checker.c +++ b/drivers/firmware/psci/psci_checker.c @@ -157,8 +157,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); @@ -167,6 +169,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