From patchwork Tue Aug 15 08:36:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 9901287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C857B6028A for ; Tue, 15 Aug 2017 08:38:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7F55287E3 for ; Tue, 15 Aug 2017 08:38:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC59B28807; Tue, 15 Aug 2017 08:38:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, URIBL_BLACK autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F233287E3 for ; Tue, 15 Aug 2017 08:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752467AbdHOIh7 (ORCPT ); Tue, 15 Aug 2017 04:37:59 -0400 Received: from lucky1.263xmail.com ([211.157.147.130]:59274 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752203AbdHOIh4 (ORCPT ); Tue, 15 Aug 2017 04:37:56 -0400 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.153]) by lucky1.263xmail.com (Postfix) with ESMTP id 5D3821EF0AB; Tue, 15 Aug 2017 16:37:50 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id CBFDB3B4; Tue, 15 Aug 2017 16:37:50 +0800 (CST) X-RL-SENDER: shawn.lin@rock-chips.com X-FST-TO: ulf.hansson@linaro.org X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: shawn.lin@rock-chips.com X-UNIQUE-TAG: <31be80bc71492da7f6133eda8df2cb8e> X-ATTACHMENT-NUM: 0 X-SENDER: lintao@rock-chips.com X-DNS-TYPE: 0 Received: from unknown (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith SMTP id 24552XO3TQ; Tue, 15 Aug 2017 16:37:51 +0800 (CST) From: Shawn Lin To: Ulf Hansson , "Rafael J. Wysocki" , Greg Kroah-Hartman Cc: Heiko Stuebner , Jaehoon Chung , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Lin Subject: [PATCH v2 1/2] driver core: detach device's pm_domain after devres_release_all Date: Tue, 15 Aug 2017 16:36:56 +0800 Message-Id: <1502786217-212887-2-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1502786217-212887-1-git-send-email-shawn.lin@rock-chips.com> References: <1502786217-212887-1-git-send-email-shawn.lin@rock-chips.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move dev_pm_domain_detach after devres_release_all to avoid accessing device's registers with genpd been powered off. Signed-off-by: Shawn Lin --- Changes in v2: None drivers/base/dd.c | 35 ++++++++++++++++++++++++++++++----- drivers/base/platform.c | 18 ++---------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index ad44b40..13dc0ad 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -25,7 +25,9 @@ #include #include #include +#include #include +#include #include #include "base.h" @@ -356,6 +358,8 @@ static int really_probe(struct device *dev, struct device_driver *drv) int local_trigger_count = atomic_read(&deferred_trigger_count); bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE) && !drv->suppress_bind_attrs; + struct platform_driver *pdrv; + bool do_pm_domain = false; if (defer_all_probes) { /* @@ -414,6 +418,16 @@ static int really_probe(struct device *dev, struct device_driver *drv) if (ret) goto probe_failed; } else if (drv->probe) { + ret = dev_pm_domain_attach(dev, true); + pdrv = to_platform_driver(dev->driver); + /* don't fail if just dev_pm_domain_attach failed */ + if (pdrv->prevent_deferred_probe && + ret == -EPROBE_DEFER) { + dev_warn(dev, "probe deferral not supported\n"); + ret = -ENXIO; + goto probe_failed; + } + do_pm_domain = true; ret = drv->probe(dev); if (ret) goto probe_failed; @@ -421,13 +435,17 @@ static int really_probe(struct device *dev, struct device_driver *drv) if (test_remove) { test_remove = false; + do_pm_domain = false; - if (dev->bus->remove) + if (dev->bus->remove) { dev->bus->remove(dev); - else if (drv->remove) + } else if (drv->remove) { drv->remove(dev); - + do_pm_domain = true; + } devres_release_all(dev); + if (do_pm_domain) + dev_pm_domain_detach(dev, true); driver_sysfs_remove(dev); dev->driver = NULL; dev_set_drvdata(dev, NULL); @@ -458,6 +476,8 @@ static int really_probe(struct device *dev, struct device_driver *drv) pinctrl_bind_failed: device_links_no_driver(dev); devres_release_all(dev); + if (do_pm_domain) + dev_pm_domain_detach(dev, true); driver_sysfs_remove(dev); dev->driver = NULL; dev_set_drvdata(dev, NULL); @@ -818,6 +838,7 @@ int driver_attach(struct device_driver *drv) static void __device_release_driver(struct device *dev, struct device *parent) { struct device_driver *drv; + bool do_pm_domain = false; drv = dev->driver; if (drv) { @@ -855,15 +876,19 @@ static void __device_release_driver(struct device *dev, struct device *parent) pm_runtime_put_sync(dev); - if (dev->bus && dev->bus->remove) + if (dev->bus && dev->bus->remove) { dev->bus->remove(dev); - else if (drv->remove) + } else if (drv->remove) { + do_pm_domain = true; drv->remove(dev); + } device_links_driver_cleanup(dev); dma_deconfigure(dev); devres_release_all(dev); + if (do_pm_domain) + dev_pm_domain_detach(dev, true); dev->driver = NULL; dev_set_drvdata(dev, NULL); if (dev->pm_domain && dev->pm_domain->dismiss) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index d1bd992..8fa688d 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -572,22 +572,8 @@ static int platform_drv_probe(struct device *_dev) if (ret < 0) return ret; - ret = dev_pm_domain_attach(_dev, true); - if (ret != -EPROBE_DEFER) { - if (drv->probe) { - ret = drv->probe(dev); - if (ret) - dev_pm_domain_detach(_dev, true); - } else { - /* don't fail if just dev_pm_domain_attach failed */ - ret = 0; - } - } - - if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) { - dev_warn(_dev, "probe deferral not supported\n"); - ret = -ENXIO; - } + if (drv->probe) + ret = drv->probe(dev); return ret; }