From patchwork Wed May 9 10:17:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 135245 Delivered-To: patches@linaro.org Received: by 10.46.151.6 with SMTP id r6csp5447889lji; Wed, 9 May 2018 03:17:59 -0700 (PDT) X-Received: by 2002:a2e:810a:: with SMTP id d10-v6mr29660375ljg.83.1525861079416; Wed, 09 May 2018 03:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525861079; cv=none; d=google.com; s=arc-20160816; b=cRW6FDjxpK0hyyeKcTF1STmF7zFascEJP4Bmf4FAqMmBgSDKCEaBQKU6YDUlU8K+5r +xXnGnA9yn5q5e4tJ00S5yQ4My9EjqTPG6l/ZVgiLgfDbhksn+hifw6TNyZdsZI2HoaM KRcSwp0nX8lC+xUTXtSGMXfWiHX5p89JxMnLPd56mirVdMsEY3k2swJT0g5LhWXY9s2c EpUlMpauOZnRx721eCYg+SOjK/9VBdWYVTdByxrfOjKubrpHWZd+fR9djYHmpzng1pcR VJQuvsDqW6FRdunnLtbGRbjLeMPDwTu1pgHTTekqWWEooYXD9wT3F9MUHGwHFI4Gp4Ca BPBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=jOQhUOLjDdH0w+vRxjijRDeLfTyJmZYgqA72ZUPe2TE=; b=W5OU7vQk1juv1bRht3PVwWxwz1oi9ewBFYFtz/9CS8uk7ZCi5G0uXGTa2tYadz+a75 p3omLlgiKkQYN/W/AkYzHlFe9RxdPYudhpyXrMF5F8nlcuWEd3nf1efYUVoB81pcmrM7 PRAC01R8ZM94I2PExH0psXJmatUXB955Px6nYNajbBOoUh4rmmsulAbeJwXxOOoH83Ek 2ZW8PFEytSwkRn7wWPFieGkQXsNA/4MVYxmqzxk+fWPjOoARAUBwWZSYyRZKz2KsPP85 GngNr83lImZnJOzdPUkcZfg1IsPv8Hhn6vFls9UZoSMnXKwRFZ/tv5UAPzjw2azFRXfq Po+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KADfCqzy; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d17-v6sor3109996lfe.44.2018.05.09.03.17.59 for (Google Transport Security); Wed, 09 May 2018 03:17:59 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KADfCqzy; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=jOQhUOLjDdH0w+vRxjijRDeLfTyJmZYgqA72ZUPe2TE=; b=KADfCqzy0J1uwzq3681N40cq7XbGS40Nt2utVSQhoczeCpd2HbTeJF5B8cgfNn/aI6 nQ7JeJ1R/stma/bPrhUjnXQNqQPgt1qYIt78CNIrtTz6cXwnAh81sdoiwdrMz2K0qufm Gwt1mWBTTeATe82Oils2p9iqniUofwzV78tr8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=jOQhUOLjDdH0w+vRxjijRDeLfTyJmZYgqA72ZUPe2TE=; b=U93CIwt6tbarBVOsCYu9qhL5nwnNUODwJZmmi74a0955HfDtyGc/uYXRq0ftYmHk3O 0LFvDjnucm1bPxY7QeZmue/G/EpkpuSGBpJ34rUfHk5nvq1DpOEx0kdOReuJiAUIPTvo 7Du1L9pL9uSIG9t5Cj49C6YC8A1+7OhI+bUdCpvFPi7Od3jO2bP99oPfS1988tKd0RGv DwN9939yHHtpRpYMCNR2Gwbl5MA3hQ3JdQGU8JEGmiJGqgJz30Lu1FpP+ZhBG39fDWND VgAA77XAfpRHcbVHDCnBa1IRRxzVfd0v/qmh+BElb0y6X21mwctUklse9Ic366TiMxis eU1w== X-Gm-Message-State: ALQs6tCfhlnccTXvMMhwvwGodL2JR9RGRxJSR2zPQCZUjRaOb1dLTgVe pxoCGgTy5cvr8DDpCUaq3q3AW7x6 X-Google-Smtp-Source: AB8JxZqyzF0INhN2ap+2/rpOYXzpkpGE3lNLS/MfHAJvb1BBcrFP78ro9MzDIYbJiQtSE48wzFO/aA== X-Received: by 2002:a19:ded9:: with SMTP id i86-v6mr13232415lfl.42.1525861078975; Wed, 09 May 2018 03:17:58 -0700 (PDT) Return-Path: Received: from localhost.localdomain (c-5eeaaa12-74736162.cust.telenor.se. [94.234.170.18]) by smtp.gmail.com with ESMTPSA id b17-v6sm5676168lfa.86.2018.05.09.03.17.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 May 2018 03:17:58 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Greg Kroah-Hartman , linux-pm@vger.kernel.org Cc: Ulf Hansson , Kevin Hilman , Geert Uytterhoeven , Viresh Kumar , Vincent Guittot , Mark Brown , Vinod Koul , Sanyog Kale , Pierre-Louis Bossart , Wolfram Sang , Russell King , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V2 05/11] PM / Domains: Allow a better error handling of dev_pm_domain_attach() Date: Wed, 9 May 2018 12:17:52 +0200 Message-Id: <1525861072-29150-1-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 The callers of dev_pm_domain_attach() currently checks the returned error code for -EPROBE_DEFER and needs to ignore other error codes. This is an unnecessary limitation, which also leads to a rather strange behaviour in the error path. Address this limitation, by changing the return codes from acpi_dev_pm_attach() and genpd_dev_pm_attach(). More precisely, let them return 0, when no PM domain is needed for the device and then return 1, in case the device was successfully attached to its PM domain. In this way, dev_pm_domain_attach(), gets a better understanding of what happens in the attach attempts and also allowing its caller to better act on real errors codes. Signed-off-by: Ulf Hansson --- Changes in v2: - Return 0 from the inline variant of dev_pm_domain_attach(), to make sure probing still works when CONFIG_PM is unset. --- drivers/acpi/device_pm.c | 6 +++--- drivers/base/power/common.c | 7 ++++--- drivers/base/power/domain.c | 19 ++++++++++--------- include/linux/acpi.h | 2 +- include/linux/pm_domain.h | 4 ++-- 5 files changed, 20 insertions(+), 18 deletions(-) -- 2.7.4 diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index d006300..a7c2673 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -1257,7 +1257,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on) struct acpi_device *adev = ACPI_COMPANION(dev); if (!adev) - return -ENODEV; + return 0; /* * Only attach the power domain to the first device if the @@ -1265,7 +1265,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on) * management twice. */ if (!acpi_device_is_first_physical_node(adev, dev)) - return -EBUSY; + return 0; acpi_add_pm_notifier(adev, dev, acpi_pm_notify_work_func); dev_pm_domain_set(dev, &acpi_general_pm_domain); @@ -1275,7 +1275,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on) } dev->pm_domain->detach = acpi_dev_pm_detach; - return 0; + return 1; } EXPORT_SYMBOL_GPL(acpi_dev_pm_attach); #endif /* CONFIG_PM */ diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index f3cf61f..5e4b481 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -98,7 +98,8 @@ EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data); * Callers must ensure proper synchronization of this function with power * management callbacks. * - * Returns 0 on successfully attached PM domain or negative error code. + * Returns 0 on successfully attached PM domain and when it found that the + * device don't need a PM domain, else a negative error code. */ int dev_pm_domain_attach(struct device *dev, bool power_on) { @@ -108,10 +109,10 @@ int dev_pm_domain_attach(struct device *dev, bool power_on) return -EEXIST; ret = acpi_dev_pm_attach(dev, power_on); - if (ret) + if (!ret) ret = genpd_dev_pm_attach(dev); - return ret; + return ret < 0 ? ret : 0; } EXPORT_SYMBOL_GPL(dev_pm_domain_attach); diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index b816adb..455ecea 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2180,10 +2180,11 @@ static void genpd_dev_pm_sync(struct device *dev) * Parse device's OF node to find a PM domain specifier. If such is found, * attaches the device to retrieved pm_domain ops. * - * Returns 0 on successfully attached PM domain or negative error code. Note - * that if a power-domain exists for the device, but it cannot be found or - * turned on, then return -EPROBE_DEFER to ensure that the device is not - * probed and to re-try again later. + * Returns 1 on successfully attached PM domain, 0 when the device don't need a + * PM domain or a negative error code in case of failures. Note that if a + * power-domain exists for the device, but it cannot be found or turned on, + * then return -EPROBE_DEFER to ensure that the device is not probed and to + * re-try again later. */ int genpd_dev_pm_attach(struct device *dev) { @@ -2192,12 +2193,12 @@ int genpd_dev_pm_attach(struct device *dev) int ret; if (!dev->of_node) - return -ENODEV; + return 0; ret = of_parse_phandle_with_args(dev->of_node, "power-domains", "#power-domain-cells", 0, &pd_args); if (ret < 0) - return ret; + return 0; mutex_lock(&gpd_list_lock); pd = genpd_get_from_provider(&pd_args); @@ -2218,7 +2219,7 @@ int genpd_dev_pm_attach(struct device *dev) if (ret != -EPROBE_DEFER) dev_err(dev, "failed to add to PM domain %s: %d", pd->name, ret); - goto out; + return ret; } dev->pm_domain->detach = genpd_dev_pm_detach; @@ -2230,8 +2231,8 @@ int genpd_dev_pm_attach(struct device *dev) if (ret) genpd_remove_device(pd, dev); -out: - return ret ? -EPROBE_DEFER : 0; + + return ret ? -EPROBE_DEFER : 1; } EXPORT_SYMBOL_GPL(genpd_dev_pm_attach); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 15bfb15..c01675b 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -899,7 +899,7 @@ static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; } static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; } static inline int acpi_dev_pm_attach(struct device *dev, bool power_on) { - return -ENODEV; + return 0; } #endif diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 04dbef9..ab18548 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -280,7 +280,7 @@ static inline int of_genpd_parse_idle_states(struct device_node *dn, static inline int genpd_dev_pm_attach(struct device *dev) { - return -ENODEV; + return 0; } static inline @@ -297,7 +297,7 @@ extern void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd); #else static inline int dev_pm_domain_attach(struct device *dev, bool power_on) { - return -ENODEV; + return 0; } static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} static inline void dev_pm_domain_set(struct device *dev,