From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DEFFC63798 for ; Tue, 27 Oct 2020 17:16:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 499E420809 for ; Tue, 27 Oct 2020 17:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603818998; bh=Yq5QBUFmeAJ3CnHOsKM943tqU9OSR3p5eyu+0akTefI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=WYDtmKOLaDuCeT+SoVRCD0ffjo5oVA9W2fO7/Mj1YaqzsoaJa2KZzEDtBBpyZIDiE 8yBC0zC82vqIg+EADnCqOMyyQ3Q9rqpoKZDRwy4B9qyEu9nXpIRk+XqXRwaUOnwyVq gbCtzbbxyEVQlp8ChG6tNIjDk6LJpDUbmpdNkQN4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1782736AbgJ0O5d (ORCPT ); Tue, 27 Oct 2020 10:57:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:45426 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763914AbgJ0Opa (ORCPT ); Tue, 27 Oct 2020 10:45:30 -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 131DD206E5; Tue, 27 Oct 2020 14:45:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809929; bh=Yq5QBUFmeAJ3CnHOsKM943tqU9OSR3p5eyu+0akTefI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=crLCQJG8xXFVqjKcPQZB3iBW4zyUbSvjKe1l75R+ImZNh6idJ2TmJUOP/nnyJG0JB zuWW4QS7zHJX/9tYzUZusUz8YCC/eU5B5ekTleYK0A+d4aqCGPgF0Mdtghe7wYGV0h KneNJdHbpiO+2iFfLjiP2rT6dvpXBB2DdRXE4Gb0= 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.4 369/408] opp: Prevent memory leak in dev_pm_opp_attach_genpd() Date: Tue, 27 Oct 2020 14:55:07 +0100 Message-Id: <20201027135512.125845924@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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 29dfaa591f8b0..8867bab72e171 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1796,6 +1796,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; @@ -1842,6 +1845,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