Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp424259pxx; Wed, 28 Oct 2020 08:04:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgpgYqjVrRVmX+Qillx7Dyml0tihSpbVngwYEjnSf1Mp033PVhI6YK3n1mAHVJT+WtNBQK X-Received: by 2002:a50:d2d3:: with SMTP id q19mr8417312edg.22.1603897453668; Wed, 28 Oct 2020 08:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603897453; cv=none; d=google.com; s=arc-20160816; b=IHfpszWWL1gTURsw4+xvBLRFcg+L2W0JyY29o2ybzbNps8YjEoaSMtzxzrSBfHaA3I OIBXpi3QXlqI0pnPMF3/SkWMT2Hwr+n3yAIesXVY9WdFViKeYUJTDdfFJLnduFdMqPME mvPLeNTWiSe/TQj4ZtQPXmTDQz+hSgSM5pZh/v5ZPpkAqiIwtORRjOL+qPel12paZCT7 7yLY4gVGKiqMfxuiFK+wjjUkU3OMI1YDAXAPiwVwhyZwGyHuqv2X0FPkiP/aa7BTxTMw vwX0Ph6EemT6qqElD+SZ2Jm1Htgk6iqe9Yrhl34HwQurjxyU7zuGxLN67IQhp4WdKyE0 2x/Q== 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=VAMSWMyLvDYm4XaJ1Lpb/2AhPBSmX4hq7+F6Xhf8Ktg=; b=MEGdq5wWjuyKz3BzSe9q4628u7YQYxs3A+6yBlDYviFuZajA1Ph5JSNkbw4TbNRRsQ 9MOOBoYVYNi7ql0JsEP4DWvq4QGK2BDJLkO3Sq1wcLX9VYeU0LLhu7Jp5N8gDGha1aOc 4VcvNZJb86EaFNdj7ta4nuFfufgL+LZ618QqU6EnrlHI/Ws8P4XdUlWBHlGeTqN2i3M+ AYQqhwdrpRGI4V3uDUJZISj4KbtMCxze08f6SM50KFek02lHv9oVH7yYivS049buoWG5 G9exLg645PH3kOPWwaKNG5fpQifMDSi+mHUFFiF/raoWEuN2PPn1ILUehwgPBfTdkQi6 CcFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hlqGCBJr; 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=fail (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 d2si2953320edn.245.2020.10.28.08.03.50; Wed, 28 Oct 2020 08:04:13 -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=hlqGCBJr; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1809722AbgJ0Q1t (ORCPT + 99 others); Tue, 27 Oct 2020 12:27:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:53084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1802814AbgJ0Pve (ORCPT ); Tue, 27 Oct 2020 11:51:34 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 A27CC2065C; Tue, 27 Oct 2020 15:51:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603813894; bh=gUnPsjpz8bbn+vtIHxWGc2snR+x1L4HKGTSAMvog4+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hlqGCBJrAt/4+oXeqUCiods9WrZyeMIblXYjc+ZOKB2Z0YTGP3k7UXtZNXJH/okRY AQb7Ee954O04O2ByBtDsbsMRmPvOR89ISWmF8Czlmz9nNd2wxjgqHIqhVrlKmLcKAo t21DnPJ0Jll6UC2qMS3QAvEKenaK8eDD+gK3GfgQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephan Gerhold , Viresh Kumar , Sasha Levin Subject: [PATCH 5.9 705/757] opp: Prevent memory leak in dev_pm_opp_attach_genpd() Date: Tue, 27 Oct 2020 14:55:55 +0100 Message-Id: <20201027135523.573660843@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@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: Viresh Kumar [ Upstream commit cb60e9602cce1593eb1e9cdc8ee562815078a354 ] If dev_pm_opp_attach_genpd() is called multiple times (once for each CPU sharing the table), then it would result in unwanted behavior like memory leak, attaching the domain multiple times, etc. Handle that by checking and returning earlier if the domains are already attached. Now that dev_pm_opp_detach_genpd() can get called multiple times as well, we need to protect that too. Note that the virtual device pointers aren't returned in this case, as they may become unavailable to some callers during the middle of the operation. Reported-by: Stephan Gerhold Signed-off-by: Viresh Kumar Signed-off-by: Sasha Levin --- drivers/opp/core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 3ca7543142bf3..1a95ad40795be 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1949,6 +1949,9 @@ static void _opp_detach_genpd(struct opp_table *opp_table) { int index; + if (!opp_table->genpd_virt_devs) + return; + for (index = 0; index < opp_table->required_opp_count; index++) { if (!opp_table->genpd_virt_devs[index]) continue; @@ -1995,6 +1998,9 @@ struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, if (!opp_table) return ERR_PTR(-ENOMEM); + if (opp_table->genpd_virt_devs) + return opp_table; + /* * If the genpd's OPP table isn't already initialized, parsing of the * required-opps fail for dev. We should retry this after genpd's OPP -- 2.25.1