Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp245509pxx; Wed, 28 Oct 2020 04:00:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0wFM79naPLSPHsjUaJaD/6HOPt/ZdVY9EsM7HfBFwZAHLHam57BUjC4CNJz5Revy1Oczm X-Received: by 2002:a17:906:6b92:: with SMTP id l18mr7091085ejr.292.1603882803160; Wed, 28 Oct 2020 04:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603882803; cv=none; d=google.com; s=arc-20160816; b=M6GzhNPibd8BbDmEn8evdJKmEWYVCaRy6SvxR0DRNLuw65a5KTfj17Q3SDYTrEUMvF y9VUI6M3YJ1VRHBf+d0iw1+RvA2woZR6sWqi1nglA0WyQbpxup4r0M8VNTU9uyNxUuOt kc2jOS472hw+b5ERnhn+w1M9L3LhCpE3KM50kYYhTmeDbEv2tctcDgr4Tg0ej9BT7UlO qamDXZ+Rx5VIr29KNwiJii3wm8x0BoOfzsL16/NQlZgt8ItTICVzNzYv4h+1WysbGE3X 2wbI9scDaefQHAahe3RbybYqN98jJbxb/lmpbgmscWmlYzq5tcnqoWCxbxCRUhWAuM2l 3TVQ== 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=r8jEFQRQtbK8uoaCi1tLFRavmgOdEK7F7CXOiyQ4I6c=; b=dXgsmi2GeMF9hehjbGgue99MPQl6FPMMslnOGK2//kPwVgIy2Xy6I3S5PY7dggvY0J 3X270jp/dFs4f0c6aLrFevYm3z7bb2cGhqvwJlJvQ8YZs9XZRSFCiIBQPu4ae+T3N6U1 UXf1z6Pfx925Hxldp7rqIZ2zBwSHxt6vv6YOZljpKf1fYtKb4wbUbVEuZRZdvg1XqOH1 XQRHxeeukBng5m4hV5aXvykZT7Xj6GMizHfmbbc1JHo6VSzd4MiVYjiT9lr6+Km26w5W nN5F0YtDy5i78xgbZojjuskiZDSlrARjlXOVyDS5Tdwyb2L8ovIL2nEuND5sJs5nF/8y Jsug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=crLCQJG8; 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 w17si2969573ejk.629.2020.10.28.03.59.41; Wed, 28 Oct 2020 04:00:03 -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=crLCQJG8; 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 S1782713AbgJ0O5b (ORCPT + 99 others); Tue, 27 Oct 2020 10:57:31 -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