From patchwork Fri Jul 14 10:51:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 107774 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp730331qge; Fri, 14 Jul 2017 03:52:03 -0700 (PDT) X-Received: by 10.98.93.136 with SMTP id n8mr4453379pfj.211.1500029523566; Fri, 14 Jul 2017 03:52:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500029523; cv=none; d=google.com; s=arc-20160816; b=ZZMsupbAYKeCxuNWL9S4dt1TFg5CWARJsxl1Rx/QY8vYCfsH2s2LH435kXSCTnKAN4 Ju7yyYTL3bONlwjHUjg3CsCAKvKL/xOxTuRUjtw3tLRSO2U0xQfCdi5ePY5WtxC7BF61 UcevJLrvKhsouwzRZuCN99KlyxKQDBBrrkh8zYm9RH9yGHsY386tdNUzzzIshgQEnZhG liFgAFCTHPA9iKYAwRdKJQRPMAiPwPZv9tOP305mK3jMvdeeqEoaaaC/kXAVh3JLrvTs TC4AOtD1S1lCUjcFP4+QJXAyHYcgyi7E6qo/lujc/ihs+mm83djeaoRkTI9zAkSzd84i Nl7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=khuDHn4ksRRESyDT6BcGR8r5kw3vzRj5cbZ7K3uNSs8=; b=xHv56RWlq76smtitVpmTokWuZpgMJb+5wuYHMSdgXoBrwe9WeIR4nyWh9tUpqSHuEo 99oud2URHp5rSgzd+7OasWQ4w33KvHpw4HOsZUI4Zy1xdXLzxlPcDZc9ZzSvcV40n/k0 HoKVwXIcFk5w2QTVYSuEMZIgYIuJC8/QQYKyfqzioLxdnJUudDD2LwjAeHbFs6jjHAkW ShUrq3yGLNqVh6TACHQmEOHMzyP6UyCCe3dD9Ygr54urPAC6KvHSrUowkswqTQePGksR 56OF+oCW2tgrHaioJbOk/NcURTD2P4icMySS9Tgwyy+cn1jzQUY2yFguE0rtMUyZ0L2m GIQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c65si6197752pfg.490.2017.07.14.03.52.03; Fri, 14 Jul 2017 03:52:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753864AbdGNKwC (ORCPT + 14 others); Fri, 14 Jul 2017 06:52:02 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:47010 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753577AbdGNKwB (ORCPT ); Fri, 14 Jul 2017 06:52:01 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C544980D; Fri, 14 Jul 2017 03:52:00 -0700 (PDT) Received: from e107155-lin.cambridge.arm.com (unknown [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BC5E93F578; Fri, 14 Jul 2017 03:51:59 -0700 (PDT) From: Sudeep Holla To: linux-pm@vger.kernel.org Cc: Sudeep Holla , "Rafael J. Wysocki" , Kevin Hilman , Ulf Hansson , "# v4 . 0+" Subject: [PATCH v2] PM / Domains: defer dev_pm_domain_set() until genpd->attach_dev succeeds if present Date: Fri, 14 Jul 2017 11:51:48 +0100 Message-Id: <1500029508-7103-1-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498759251-11709-1-git-send-email-sudeep.holla@arm.com> References: <1498759251-11709-1-git-send-email-sudeep.holla@arm.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org If the genpd->attach_dev or genpd->power_on fails, genpd_dev_pm_attach may return -EPROBE_DEFER initially. However genpd_alloc_dev_data sets the PM domain for the device unconditionally. When subsequent attempts are made to call genpd_dev_pm_attach, it may return -EEXISTS checking dev->pm_domain without re-attempting to call attach_dev or power_on. platform_drv_probe then attempts to call drv->probe as the return value -EEXIST != -EPROBE_DEFER, which may end up in a situation where the device is accessed without it's power domain switched on. Fixes: f104e1e5ef57 ("PM / Domains: Re-order initialization of generic_pm_domain_data") Cc: "Rafael J. Wysocki" Cc: Kevin Hilman Cc: Ulf Hansson Cc: # v4.0+ Signed-off-by: Sudeep Holla --- drivers/base/power/domain.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) Hi, I have added Cc/Fixes tags based on the original commit that caused the issue. I need to workout a patch that can cleanly apply before commit 989561de9b51 ("PM / Domains: add setter for dev.pm_domain"), i.e. for v4.0.x to v4.4.x This patch should apply from v4.5.x onwards. Let me know if I got anything wrong. v1->v2: Moved dev_pm_domain_set(dev, NULL) from genpd_free_dev_data Regards, Sudeep -- 2.7.4 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index da49a8383dc3..2d9178660061 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1168,8 +1168,6 @@ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev, spin_unlock_irq(&dev->power.lock); - dev_pm_domain_set(dev, &genpd->domain); - return gpd_data; err_free: @@ -1183,8 +1181,6 @@ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev, static void genpd_free_dev_data(struct device *dev, struct generic_pm_domain_data *gpd_data) { - dev_pm_domain_set(dev, NULL); - spin_lock_irq(&dev->power.lock); dev->power.subsys_data->domain_data = NULL; @@ -1221,6 +1217,8 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, if (ret) goto out; + dev_pm_domain_set(dev, &genpd->domain); + genpd->device_count++; genpd->max_off_time_changed = true; @@ -1282,6 +1280,8 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, if (genpd->detach_dev) genpd->detach_dev(genpd, dev); + dev_pm_domain_set(dev, NULL); + list_del_init(&pdd->list_node); genpd_unlock(genpd);