From patchwork Wed Sep 21 13:38:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 76685 Delivered-To: patches@linaro.org Received: by 10.140.106.72 with SMTP id d66csp2056341qgf; Wed, 21 Sep 2016 06:39:01 -0700 (PDT) X-Received: by 10.46.5.130 with SMTP id 124mr13966136ljf.45.1474465141200; Wed, 21 Sep 2016 06:39:01 -0700 (PDT) Return-Path: Received: from mail-lf0-x234.google.com (mail-lf0-x234.google.com. [2a00:1450:4010:c07::234]) by mx.google.com with ESMTPS id f80si171855lfg.82.2016.09.21.06.39.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Sep 2016 06:39:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::234 as permitted sender) client-ip=2a00:1450:4010:c07::234; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::234 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x234.google.com with SMTP id l131so41515912lfl.2 for ; Wed, 21 Sep 2016 06:39:01 -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=+kiq0v1miAK1B2zrsPbEPk/bdrb7XYMCMuX4FPPSWo8=; b=FXcbH+SmJacniuSPPK5FXY145yRcfz/nIjNk0BOwPcjEZDGNYtGEO8mKDASS4f6OIs UXNPFbruAqSE7ofm/uaefLPA+V1vNg6Zw3to9fYIfs/MXox9YxKOAdcDrFiBLPDSXNeM NsXcfWnaCG/6EcGjpZP9HVAxEsQj9Uq+Ya4eE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+kiq0v1miAK1B2zrsPbEPk/bdrb7XYMCMuX4FPPSWo8=; b=W/d7ORb1HRFgOfxcP7UebrS362gVaZ8k2I2ZtNmXSnY3YM2x4NkS3qz1eBPtNjDdoc 7UX2sJYjH1hJhG4Jk18P3s0sUlbjKfASuztu7/NRbyyB7lGjLRAJjEp/mnKP1NYh8EQl e/uPt/OpIiqSo7OLYPf8zAr9EKay9UFzRwCcGh8Yno/VxG69UrMdTjJwuGlXoijxIbCM BBYe1G4gofPnMvGCOgjhBOY60k27/tFn4eH7nf5mdLFx0IWdWraoiN2M4fDLFecGr5CW 5gLLR9HdzZQPUfxYc23PvU4COG1FBvCLL5So4Bjj3TbFh73W2Z2ip2v33/zVr+zSKA57 7G+A== X-Gm-Message-State: AE9vXwNSr7RQV59+SW1cHN0gAvmXfQr78FTIH3SacB+eXBM+5eQAyQk281DXDZ6NieVyt/cOwkM= X-Received: by 10.46.69.69 with SMTP id s66mr6924561lja.26.1474465140765; Wed, 21 Sep 2016 06:39:00 -0700 (PDT) Return-Path: Received: from uffe-Latitude-E6430s.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id s125sm6710569lja.14.2016.09.21.06.38.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Sep 2016 06:38:59 -0700 (PDT) From: Ulf Hansson To: "Rafael J. Wysocki" , Kevin Hilman , Ulf Hansson , linux-pm@vger.kernel.org Cc: Len Brown , Pavel Machek , Geert Uytterhoeven , Lina Iyer , Jon Hunter Subject: [PATCH 1/4] PM / Domains: Simplify detaching a device from its genpd Date: Wed, 21 Sep 2016 15:38:50 +0200 Message-Id: <1474465133-14865-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1474465133-14865-1-git-send-email-ulf.hansson@linaro.org> References: <1474465133-14865-1-git-send-email-ulf.hansson@linaro.org> There's no need to validate the PM domain by using genpd_lookup_dev() when removing the device via genpd's genpd_dev_pm_detach() function. That's because this function can't be called, unless there is a valid PM domain for the device. To simplify the behaviour, let's move code from pm_genpd_remove_device() into a new internal function, genpd_remove_device(), which is called from pm_genpd_remove_device() and genpd_dev_pm_detach(). Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) -- 1.9.1 Reviewed-by: Lina Iyer diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 83ae3d7..63f0f8b 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1121,13 +1121,8 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, } EXPORT_SYMBOL_GPL(__pm_genpd_add_device); -/** - * pm_genpd_remove_device - Remove a device from an I/O PM domain. - * @genpd: PM domain to remove the device from. - * @dev: Device to be removed. - */ -int pm_genpd_remove_device(struct generic_pm_domain *genpd, - struct device *dev) +static int genpd_remove_device(struct generic_pm_domain *genpd, + struct device *dev) { struct generic_pm_domain_data *gpd_data; struct pm_domain_data *pdd; @@ -1135,10 +1130,6 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, dev_dbg(dev, "%s()\n", __func__); - if (!genpd || genpd != genpd_lookup_dev(dev)) - return -EINVAL; - - /* The above validation also means we have existing domain_data. */ pdd = dev->power.subsys_data->domain_data; gpd_data = to_gpd_data(pdd); dev_pm_qos_remove_notifier(dev, &gpd_data->nb); @@ -1170,6 +1161,20 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, return ret; } + +/** + * pm_genpd_remove_device - Remove a device from an I/O PM domain. + * @genpd: PM domain to remove the device from. + * @dev: Device to be removed. + */ +int pm_genpd_remove_device(struct generic_pm_domain *genpd, + struct device *dev) +{ + if (!genpd || genpd != genpd_lookup_dev(dev)) + return -EINVAL; + + return genpd_remove_device(genpd, dev); +} EXPORT_SYMBOL_GPL(pm_genpd_remove_device); static int genpd_add_subdomain(struct generic_pm_domain *genpd, @@ -1797,14 +1802,14 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off) unsigned int i; int ret = 0; - pd = genpd_lookup_dev(dev); - if (!pd) + pd = dev_to_genpd(dev); + if (IS_ERR(pd)) return; dev_dbg(dev, "removing from PM domain %s\n", pd->name); for (i = 1; i < GENPD_RETRY_MAX_MS; i <<= 1) { - ret = pm_genpd_remove_device(pd, dev); + ret = genpd_remove_device(pd, dev); if (ret != -EAGAIN) break;