Received: by 10.192.165.148 with SMTP id m20csp1771950imm; Thu, 26 Apr 2018 01:56:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx49TJYgkY9PL7n3uZrg4kgQ8L5VTMuiLj6xX43kBAN7aVkUPOhKrlyPMamkARzTgzBkQjH/m X-Received: by 10.99.140.77 with SMTP id q13mr26619834pgn.44.1524733007052; Thu, 26 Apr 2018 01:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524733007; cv=none; d=google.com; s=arc-20160816; b=PBCRo3NFOx5yse9MUDmMjR9qet/rgJmO5We1AuQATbMTMvRTGrfc/dCsWqPBF8Fvhk s4MBQw6/cW6rx2g/Ees49A6mFg8oXEfPWlqUeVFyXav3JkaR7aA89ADKHcV4EvI0UcEN 2lIkJbHPclsOo7x7X7uNu11XsO4N9ewW5zkcArGTbIDeH7ft15Dbzy9MScPDbGWw3CVi 1WyZk9JM+1OByULl4qwT5Z885/aYhtFE3Ede/SQsE7RmjJt2bGRerb+j7I8wvfOQktPK WjpJCB6mld1xaRzTvkD2HE+G4uxUf05McBDbtbKNjXgzJ8o/4wERcOk1eCqz9meFatqB THBQ== 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:dkim-signature:arc-authentication-results; bh=myhUo+RRBuBr1W4j3dNgjvpKR9j5RD+zME8+Uz1EWlA=; b=uht5pdKu3J2RiY0SkSnNaSuKWgZzLdKQz+LVRSD/bzQf6hC2zOfUr1zA7z7mjgjaPK wdk2c5GZu0lgOAf+4wuCRXv0WrM1DOBM9iPEHfQ+/uM5Hg3AribBgiXmftfxp8FHFa/e g+yVXizstx21nUd86KQGqcwWsmupNIkDFXwpjebyn/BMPlU2cWo5oyiyOFkDsGGkMEwa j0ZHEyKSwm1nmWIqzMWZ3uYwG8Psck8XUEnaWQho6GYfArJR6sssbP3yW2wXvYYEIp96 oT2A/7siJjh/3gu3iSI6bIOzcLwmiWzjDeEcCe9FdAIBvfpQNUSxhZIGuFuf6yfPIQx8 7+Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jByH7P3D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q5si15680504pgc.620.2018.04.26.01.56.32; Thu, 26 Apr 2018 01:56:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jByH7P3D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754801AbeDZIxe (ORCPT + 99 others); Thu, 26 Apr 2018 04:53:34 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:38129 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754587AbeDZIxY (ORCPT ); Thu, 26 Apr 2018 04:53:24 -0400 Received: by mail-lf0-f67.google.com with SMTP id z130-v6so29546072lff.5 for ; Thu, 26 Apr 2018 01:53:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=myhUo+RRBuBr1W4j3dNgjvpKR9j5RD+zME8+Uz1EWlA=; b=jByH7P3DzOotnPMjCYUIpL4xMIbWmjIyyByhpxOPqK7fNrQDTJ079SmiQh/9oo5qD1 KEo0e81ihoXTx5di5XNiYZ5kdh9kpT1/Uk/3pe/oGuX5xsaRInYYLTmNT3AcMae8TJv4 FHO78zgjP9/r+VJWqgrHL0mFbzdvjSgBGG1Po= 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:in-reply-to :references; bh=myhUo+RRBuBr1W4j3dNgjvpKR9j5RD+zME8+Uz1EWlA=; b=CzHlI0SRpdA+hyV060OxaPCi2/cQmvLDmIboOfZl9+UyGbe6TtKrBXcD22x1ITII0X qjKEMR857X5ZSBLoipTlq0r1OUgUkdPFGd/0//Xa14uJ9hOuaBunVk9AN9FpQnB7veIV Hc7ueYguoT/xIZ0JxUCl7IeR4wHbqzKcfKZhMtNcoM9enuJ091s2RA/OVpONE8S+MWc7 DlLYi/r44M5CqynpQliUTzMVTJjW8qb0k1oZSjrfIACQHAQKDpWJLmoZ7u6QVoc7BjH8 UQt8auYiowAZZ4MKCk8h9LCHcT4gzorD0Nztck6FKPnHgB3ZUb9+oyixP7lDQCohPXZX ureA== X-Gm-Message-State: ALQs6tDEya2Y9mvpkSNtu2r83fjOa4ckkUFsyvNabEeegopBuDX84rEW CLREdhSeLhe6BU03U1h/+Ef3UA== X-Received: by 2002:a19:9b51:: with SMTP id d78-v6mr13646312lfe.66.1524732802713; Thu, 26 Apr 2018 01:53:22 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id u83-v6sm681097lff.65.2018.04.26.01.53.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Apr 2018 01:53:21 -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 05/11] PM / Domains: Allow a better error handling of dev_pm_domain_attach() Date: Thu, 26 Apr 2018 10:53:04 +0200 Message-Id: <1524732790-2234-6-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524732790-2234-1-git-send-email-ulf.hansson@linaro.org> References: <1524732790-2234-1-git-send-email-ulf.hansson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 | 2 +- 5 files changed, 19 insertions(+), 17 deletions(-) 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..a1da66e 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 -- 2.7.4