From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752043AbdFLNKG (ORCPT ); Mon, 12 Jun 2017 09:10:06 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:33902 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751494AbdFLNKE (ORCPT ); Mon, 12 Jun 2017 09:10:04 -0400 Date: Mon, 12 Jun 2017 15:10:00 +0200 From: Krzysztof Kozlowski To: Ulf Hansson Cc: "Rafael J. Wysocki" , Kevin Hilman , Pavel Machek , Len Brown , Greg Kroah-Hartman , "linux-pm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 2/8] PM / domains: Protect reading loop over list of domains Message-ID: <20170612131000.GA22241@kozik-book> References: <20170609160853.31789-1-krzk@kernel.org> <20170609160853.31789-3-krzk@kernel.org> <20170609161649.g5wjn24tm2opyq3h@kozik-lap> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 12, 2017 at 02:57:21PM +0200, Ulf Hansson wrote: > On 9 June 2017 at 18:16, Krzysztof Kozlowski wrote: > > On Fri, Jun 09, 2017 at 06:08:47PM +0200, Krzysztof Kozlowski wrote: > >> The pm_genpd_present() iterates over list of domains so grabbing a > >> gpd_list_lock mutex is necessary before calling it. Otherwise we could > >> end up in iterating over and modifying the list at the same time. > >> > >> Signed-off-by: Krzysztof Kozlowski > >> --- > >> drivers/base/power/domain.c | 7 ++++++- > >> 1 file changed, 6 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c > >> index 2e8d0f423507..2a6935dc0164 100644 > >> --- a/drivers/base/power/domain.c > >> +++ b/drivers/base/power/domain.c > >> @@ -1099,8 +1099,13 @@ static void genpd_syscore_switch(struct device *dev, bool suspend) > >> struct generic_pm_domain *genpd; > >> > >> genpd = dev_to_genpd(dev); > > Actually there may be potential problem here as we may end up trying > to use the container_of() call for a PM domain, not being a genpd but > something else. > > >> - if (!pm_genpd_present(genpd)) > >> + > >> + mutex_lock(&gpd_list_lock); > >> + if (!pm_genpd_present(genpd)) { > >> + mutex_unlock(&gpd_list_lock); > >> return; > >> + } > >> + mutex_unlock(&gpd_list_lock); > > Perhaps convert the hole thing above to call genpd_lookup_dev() instead? Indeed, that would solve both problems. Thanks, I'll fix this. Best regards, Krzysztof