From patchwork Tue Oct 28 14:38:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 39671 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E13E824046 for ; Tue, 28 Oct 2014 14:38:28 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id m15sf530105wgh.8 for ; Tue, 28 Oct 2014 07:38:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=5RrNDiaGAvu+73toxyvQcY3xh/u/ObJ9k1GVNs3r/rY=; b=KeJBrssTDkr/ZsyEkrt++i8cNBKDLPbbWM1a6AFxjAO5+gv2CjEsceAN5jkcs3YiyN lzRtmjxGDuzX82lB7xnSKftnKJj/1/4UV8GbJLkES4yqZd5P0fPPd/+PyeWN2/4+HSGZ vr1H5hXI2669EQ/sjbLV8wtjWQqR1gzXF1S+UTqIdK7FAVcz85QtgT52TL3jpeUiTJVp Z729UOecKkvBHaVgdaFbGo0DQ8kQq24/65m0+hU2Ef+UFRXN3EGzYQ1baHgtZhoMh/6O p/QuSZET080rE6on1cVfu8MSo/vEwn/JiqiA+zJbR+wXfj6tdsU1IzdWDdFkoL1QLtHW NtmA== X-Gm-Message-State: ALoCoQkvZg7tr1bUDWpRd+8ZEezFZiWt7BGwCAPRxkSTSFEDUgr7xQaVyeyCXpgwRhAL0pxOXojt X-Received: by 10.152.3.168 with SMTP id d8mr711838lad.0.1414507108034; Tue, 28 Oct 2014 07:38:28 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.100 with SMTP id z4ls67330laz.60.gmail; Tue, 28 Oct 2014 07:38:27 -0700 (PDT) X-Received: by 10.112.77.129 with SMTP id s1mr4657296lbw.36.1414507107809; Tue, 28 Oct 2014 07:38:27 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id u2si2840408lal.70.2014.10.28.07.38.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 28 Oct 2014 07:38:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id gf13so746974lab.17 for ; Tue, 28 Oct 2014 07:38:27 -0700 (PDT) X-Received: by 10.112.14.69 with SMTP id n5mr4532908lbc.34.1414507107711; Tue, 28 Oct 2014 07:38:27 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.84.229 with SMTP id c5csp492334lbz; Tue, 28 Oct 2014 07:38:27 -0700 (PDT) X-Received: by 10.112.198.226 with SMTP id jf2mr4533719lbc.84.1414507106085; Tue, 28 Oct 2014 07:38:26 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id p8si2849530lag.62.2014.10.28.07.38.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 28 Oct 2014 07:38:26 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id gm9so719648lab.41 for ; Tue, 28 Oct 2014 07:38:26 -0700 (PDT) X-Received: by 10.152.19.9 with SMTP id a9mr4493179lae.41.1414507105960; Tue, 28 Oct 2014 07:38:25 -0700 (PDT) Received: from uffe-Latitude-E6430s.lan (90-231-160-185-no158.tbcn.telia.com. [90.231.160.185]) by mx.google.com with ESMTPSA id qg4sm680886lbb.36.2014.10.28.07.38.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Oct 2014 07:38:25 -0700 (PDT) From: Ulf Hansson To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , linux-pm@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Geert Uytterhoeven , Kevin Hilman , Alan Stern , Greg Kroah-Hartman , Tomasz Figa , Simon Horman , Magnus Damm , Ben Dooks , Kukjin Kim , Philipp Zabel , Mark Brown , Wolfram Sang , Russell King , Dmitry Torokhov , Jack Dai , Jinkun Hong , Aaron Lu , Sylwester Nawrocki , Ulf Hansson Subject: [PATCH 3/4] PM / Domains: Improve error handling while adding/removing devices Date: Tue, 28 Oct 2014 15:38:09 +0100 Message-Id: <1414507090-516-4-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1414507090-516-1-git-send-email-ulf.hansson@linaro.org> References: <1414507090-516-1-git-send-email-ulf.hansson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ulf.hansson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , To improve error handling while adding/removing devices from their PM domains, we need to restructure the code a bit. Let's do this by moving the device specific parts into a separate function. Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 132 +++++++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 63 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 9d511c7..4e5fcd7 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1358,25 +1358,81 @@ EXPORT_SYMBOL_GPL(pm_genpd_syscore_poweron); #endif /* CONFIG_PM_SLEEP */ -static struct generic_pm_domain_data *__pm_genpd_alloc_dev_data(struct device *dev) +static int genpd_alloc_dev_data(struct generic_pm_domain *genpd, + struct device *dev, struct gpd_timing_data *td) { struct generic_pm_domain_data *gpd_data; + int ret; + + dev_dbg(dev, "%s()\n", __func__); + + ret = dev_pm_get_subsys_data(dev); + if (ret) + return ret; gpd_data = kzalloc(sizeof(*gpd_data), GFP_KERNEL); - if (!gpd_data) - return NULL; + if (!gpd_data) { + ret = -ENOMEM; + goto err_alloc; + } mutex_init(&gpd_data->lock); + gpd_data->base.dev = dev; + gpd_data->td.constraint_changed = true; + gpd_data->td.effective_constraint_ns = -1; gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier; + if (td) + gpd_data->td = *td; + + spin_lock_irq(&dev->power.lock); + if (!dev->power.subsys_data->domain_data) + dev->power.subsys_data->domain_data = &gpd_data->base; + else + ret = -EINVAL; + spin_unlock_irq(&dev->power.lock); + + if (ret) + goto err_data; + + if (genpd->attach_dev) + genpd->attach_dev(dev); + dev_pm_qos_add_notifier(dev, &gpd_data->nb); - return gpd_data; + return 0; + + err_data: + kfree(gpd_data); + err_alloc: + dev_pm_put_subsys_data(dev); + return ret; } -static void __pm_genpd_free_dev_data(struct device *dev, - struct generic_pm_domain_data *gpd_data) +static void genpd_free_dev_data(struct generic_pm_domain *genpd, + struct device *dev) { + struct generic_pm_domain_data *gpd_data; + struct pm_domain_data *pdd; + + dev_dbg(dev, "%s()\n", __func__); + + if (genpd->detach_dev) + genpd->detach_dev(dev); + + spin_lock_irq(&dev->power.lock); + dev->pm_domain = NULL; + pdd = dev->power.subsys_data->domain_data; + list_del_init(&pdd->list_node); + gpd_data = to_gpd_data(pdd); + dev->power.subsys_data->domain_data = NULL; + spin_unlock_irq(&dev->power.lock); + + mutex_lock(&gpd_data->lock); + pdd->dev = NULL; + mutex_unlock(&gpd_data->lock); + dev_pm_qos_remove_notifier(dev, &gpd_data->nb); kfree(gpd_data); + dev_pm_put_subsys_data(dev); } /** @@ -1388,7 +1444,7 @@ static void __pm_genpd_free_dev_data(struct device *dev, int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, struct gpd_timing_data *td) { - struct generic_pm_domain_data *gpd_data_new, *gpd_data = NULL; + struct generic_pm_domain_data *gpd_data; struct pm_domain_data *pdd; int ret = 0; @@ -1397,10 +1453,6 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev)) return -EINVAL; - gpd_data_new = __pm_genpd_alloc_dev_data(dev); - if (!gpd_data_new) - return -ENOMEM; - genpd_acquire_lock(genpd); if (genpd->prepared_count > 0) { @@ -1414,46 +1466,25 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, goto out; } - ret = dev_pm_get_subsys_data(dev); + ret = genpd_alloc_dev_data(genpd, dev, td); if (ret) goto out; - genpd->device_count++; - genpd->max_off_time_changed = true; - spin_lock_irq(&dev->power.lock); - - if (dev->power.subsys_data->domain_data) { - ret = -EINVAL; - goto out; - } else { - gpd_data = gpd_data_new; - dev->power.subsys_data->domain_data = &gpd_data->base; - } - if (td) - gpd_data->td = *td; - dev->pm_domain = &genpd->domain; - + gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); spin_unlock_irq(&dev->power.lock); - if (genpd->attach_dev) - genpd->attach_dev(dev); - mutex_lock(&gpd_data->lock); - gpd_data->base.dev = dev; list_add_tail(&gpd_data->base.list_node, &genpd->dev_list); gpd_data->need_restore = genpd->status == GPD_STATE_POWER_OFF; - gpd_data->td.constraint_changed = true; - gpd_data->td.effective_constraint_ns = -1; mutex_unlock(&gpd_data->lock); + genpd->device_count++; + genpd->max_off_time_changed = true; + out: genpd_release_lock(genpd); - - if (gpd_data != gpd_data_new) - __pm_genpd_free_dev_data(dev, gpd_data_new); - return ret; } @@ -1477,8 +1508,6 @@ int __pm_genpd_name_add_device(const char *domain_name, struct device *dev, int pm_genpd_remove_device(struct generic_pm_domain *genpd, struct device *dev) { - struct generic_pm_domain_data *gpd_data; - struct pm_domain_data *pdd; int ret = 0; dev_dbg(dev, "%s()\n", __func__); @@ -1498,33 +1527,10 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, genpd->device_count--; genpd->max_off_time_changed = true; - if (genpd->detach_dev) - genpd->detach_dev(dev); - - spin_lock_irq(&dev->power.lock); - - dev->pm_domain = NULL; - pdd = dev->power.subsys_data->domain_data; - list_del_init(&pdd->list_node); - gpd_data = to_gpd_data(pdd); - dev->power.subsys_data->domain_data = NULL; - - spin_unlock_irq(&dev->power.lock); - - mutex_lock(&gpd_data->lock); - pdd->dev = NULL; - mutex_unlock(&gpd_data->lock); - - genpd_release_lock(genpd); - - dev_pm_put_subsys_data(dev); - __pm_genpd_free_dev_data(dev, gpd_data); - - return 0; + genpd_free_dev_data(genpd, dev); out: genpd_release_lock(genpd); - return ret; }