From patchwork Thu Sep 3 19:58:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 7119051 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B6F929F1CD for ; Thu, 3 Sep 2015 20:01:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB0FE203A5 for ; Thu, 3 Sep 2015 20:01:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7CA49204AD for ; Thu, 3 Sep 2015 20:01:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZXafC-0008GA-Uu; Thu, 03 Sep 2015 19:59:14 +0000 Received: from mail-pa0-f47.google.com ([209.85.220.47]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZXaf4-00088e-KI for linux-arm-kernel@lists.infradead.org; Thu, 03 Sep 2015 19:59:07 +0000 Received: by pacwi10 with SMTP id wi10so207744pac.3 for ; Thu, 03 Sep 2015 12:58:46 -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:mime-version:content-type:content-transfer-encoding; bh=K6DuRnYvsULANNMPo1pX6CruC+5hEoauZj93P4FPrSk=; b=MXU7MgsfJG6fE7xz8JCjkwBwza5GEsoyxwbiDk2PsMl2gudQ6XrMxsIPLKmQOgF6R0 ZiMTCVQxRBTH/eGjYbejp9BHhRC/N0H4DRUrCJSfMfU3Ygjw1se3Rt8XO7zTHY49PGUb g1A2Id6JCSI6IMseHO4U2/kVq4ALbegqWEU1y593QfPNVnKjjyuHyIcvqL2hWtGqEC9F w8nrwaHA2+hImGZvXe+GI2ZB8zsvzwEPe9etC3URaxbSTzxoHQp6IWX+46icKOgx/LhY /cwuL+57BXyCy1g3CsjmHHVFk3bYTKfW0t9Gk+nSdstkcHNNCKHs39mKKVdRG84Z2VFF hzPg== X-Gm-Message-State: ALoCoQkoY82BQF4kWiTnofeDomILyyG4aOu8saLOaKR559496oN7aMZO2keWzh8W0a8bFNhmRFb5 X-Received: by 10.66.241.2 with SMTP id we2mr70945753pac.99.1441310325891; Thu, 03 Sep 2015 12:58:45 -0700 (PDT) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id a17sm13396430pbu.55.2015.09.03.12.58.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Sep 2015 12:58:45 -0700 (PDT) From: Lina Iyer To: ulf.hansson@linaro.org, khilman@linaro.org, linux-pm@vger.kernel.org Subject: [PATCH v2 1/7] PM / Domains: Allocate memory outside domain locks Date: Thu, 3 Sep 2015 13:58:28 -0600 Message-Id: <1441310314-8857-2-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1441310314-8857-1-git-send-email-lina.iyer@linaro.org> References: <1441310314-8857-1-git-send-email-lina.iyer@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150903_125906_694717_5246FEFF X-CRM114-Status: GOOD ( 14.65 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: k.kozlowski@samsung.com, sboyd@codeaurora.org, rjw@rjwysocki.net, msivasub@codeaurora.org, geert@linux-m68k.org, Lina Iyer , agross@codeaurora.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_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 In preparation for supporting IRQ-safe domains, allocate domain data outside the domain locks. These functions are not called in an atomic context, so we can always allocate memory using GFP_KERNEL. By allocating memory before the locks, we can safely lock the domain using spinlocks instead of mutexes. Cc: Ulf Hansson Cc: Rafael J. Wysocki Cc: Kevin Hilman Cc: Geert Uytterhoeven Cc: Krzysztof Koz?owski Reviewed-by: Kevin Hilman Acked-by: Ulf Hansson Signed-off-by: Lina Iyer --- drivers/base/power/domain.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index e45a0ef..ef8d19f 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1381,13 +1381,17 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd, int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, struct generic_pm_domain *subdomain) { - struct gpd_link *link; + struct gpd_link *link, *itr; int ret = 0; if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain) || genpd == subdomain) return -EINVAL; + link = kzalloc(sizeof(*link), GFP_KERNEL); + if (!link) + return -ENOMEM; + mutex_lock(&genpd->lock); mutex_lock_nested(&subdomain->lock, SINGLE_DEPTH_NESTING); @@ -1397,18 +1401,13 @@ int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, goto out; } - list_for_each_entry(link, &genpd->master_links, master_node) { - if (link->slave == subdomain && link->master == genpd) { + list_for_each_entry(itr, &genpd->master_links, master_node) { + if (itr->slave == subdomain && itr->master == genpd) { ret = -EINVAL; goto out; } } - link = kzalloc(sizeof(*link), GFP_KERNEL); - if (!link) { - ret = -ENOMEM; - goto out; - } link->master = genpd; list_add_tail(&link->master_node, &genpd->master_links); link->slave = subdomain; @@ -1419,7 +1418,8 @@ int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, out: mutex_unlock(&subdomain->lock); mutex_unlock(&genpd->lock); - + if (ret) + kfree(link); return ret; } @@ -1510,17 +1510,17 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state) if (IS_ERR_OR_NULL(genpd) || state < 0) return -EINVAL; + cpuidle_data = kzalloc(sizeof(*cpuidle_data), GFP_KERNEL); + if (!cpuidle_data) + return -ENOMEM; + mutex_lock(&genpd->lock); if (genpd->cpuidle_data) { ret = -EEXIST; - goto out; - } - cpuidle_data = kzalloc(sizeof(*cpuidle_data), GFP_KERNEL); - if (!cpuidle_data) { - ret = -ENOMEM; - goto out; + goto err_drv; } + cpuidle_drv = cpuidle_driver_ref(); if (!cpuidle_drv) { ret = -ENODEV;