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: 5177661 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3FDA7C11AC for ; Tue, 28 Oct 2014 14:38:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6EA1920274 for ; Tue, 28 Oct 2014 14:38:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2D21420254 for ; Tue, 28 Oct 2014 14:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754276AbaJ1Oi2 (ORCPT ); Tue, 28 Oct 2014 10:38:28 -0400 Received: from mail-la0-f44.google.com ([209.85.215.44]:51745 "EHLO mail-la0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753639AbaJ1Oi1 (ORCPT ); Tue, 28 Oct 2014 10:38:27 -0400 Received: by mail-la0-f44.google.com with SMTP id gf13so756842lab.3 for ; Tue, 28 Oct 2014 07:38:26 -0700 (PDT) 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=5RrNDiaGAvu+73toxyvQcY3xh/u/ObJ9k1GVNs3r/rY=; b=TdI7wmDKKE4iNxbX9VLkU0rX+zI+Io1v/FrHosU416VU7M13sTh5we2We7AF9BySK8 /F6vekTubpnGdMRMS7058kkFkRRzAFCgOzF+5jdXtAnjrKfcP5NCeWQ4bEl/3AStBR1U McIJm3ZWXMJ2TrqNKYsfhnPBMdFUj/epA0tWsaSUmm98Eq0+pt63O45nEA11cHN5aIcu YysVcjK8vDgjtPlhU3C9usXaCgh3SvImKRllbR//ftKnmJxhvlX5FZeQ13Gx9QIyNwhe jc2Rm6kM3XZ1RtyPZM+IinsydugBsFzXtv2NPermDzofv4bRzMi8YnpJY4qShzb0Z3ig Jufg== X-Gm-Message-State: ALoCoQmKqVCgIiGw1fsVAVj8qamzgzsfCROyTKX0cu2NJabRrw8b72pIueGZ0LPBITvNj860ONJI 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> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; }