From patchwork Mon Jan 23 04:41:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 9531715 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 623B96020B for ; Mon, 23 Jan 2017 04:42:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 545AB27EED for ; Mon, 23 Jan 2017 04:42:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48C0F27E3E; Mon, 23 Jan 2017 04:42:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4069D279E0 for ; Mon, 23 Jan 2017 04:42:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751054AbdAWEma (ORCPT ); Sun, 22 Jan 2017 23:42:30 -0500 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36592 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751047AbdAWEm2 (ORCPT ); Sun, 22 Jan 2017 23:42:28 -0500 Received: by mail-pf0-f170.google.com with SMTP id 189so37930012pfu.3 for ; Sun, 22 Jan 2017 20:42:22 -0800 (PST) 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 :in-reply-to:references; bh=M+MdySlyYr6QsNJtXqp2XYTDAY4CUHc4r0SJ8CHtITQ=; b=YXkYJA69rPjnqrXUOJ98BhHZHKPOxS2i/Gt86P/g6OSXRM9oR5SUNF1oMt7SfMuah6 WQ/ODIIb9iJ6Qr1O80NK15zX2HiG8bvnk3Pp47qL9F1hLuWawdD3oWr7kmiiJPG9QgZe T0BQS8N2CAvUvzIoAOSKkUemxxdY43uf2X6mI= 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:in-reply-to:references; bh=M+MdySlyYr6QsNJtXqp2XYTDAY4CUHc4r0SJ8CHtITQ=; b=hMvLXax62ZpAxWRM5Zt5CVwYI1zNjTT5IPaIyGetO8pnG9rsJvhSHR63axzZsTOIg5 hwtTP4hz3hBbDlLNdlA0fCGLH+3yYl+jzcTG+5E+BErANLmcLvUsgbKJs5EdW+UG4N7a 6pdQxQh82WuIT1WpWcBrn0g/n9ynxFFEjrMyHp8ijxj+uxkjezxEJ4DkS8uZZGCykHDo mB45S623bNPtLzgCsUiq9CtS+88ix+iFvrGwy1k2dAQOurQir5nAr7qH03UTO/hsBn4e jpRnsNkD6uN+LxYSYhybuxidEBbATymKH+GBpAuRRqj+s9VxOqwRXm9BZnmAdFDYZh4B zB2w== X-Gm-Message-State: AIkVDXIJGVIw8izyHTJYlLeP6WmmOTceUhq40yoj1sYPdu20H01O7Wbl1MIW/qKfQ9fHK32m X-Received: by 10.84.199.194 with SMTP id d2mr40292422plh.134.1485146537206; Sun, 22 Jan 2017 20:42:17 -0800 (PST) Received: from localhost ([122.171.65.82]) by smtp.gmail.com with ESMTPSA id f65sm32764558pfk.5.2017.01.22.20.42.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Jan 2017 20:42:16 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Viresh Kumar Subject: [PATCH V2 05/12] PM / OPP: Use dev_pm_opp_get_opp_table() instead of _add_opp_table() Date: Mon, 23 Jan 2017 10:11:45 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Migrate all users of _add_opp_table() to use dev_pm_opp_get_opp_table() to guarantee that the OPP table doesn't get freed while being used. Also update _managed_opp() to get the reference to the OPP table. Now that the OPP table wouldn't get freed while these routines are executing after dev_pm_opp_get_opp_table() is called, there is no need to take opp_table_lock. Drop them as well. Now that _add_opp_table(), _remove_opp_table() and the unlocked release routines aren't used anymore, remove them. Signed-off-by: Viresh Kumar Reviewed-by: Stephen Boyd --- drivers/base/power/opp/core.c | 63 ++++--------------------------------------- drivers/base/power/opp/of.c | 54 +++++++++++++++++-------------------- drivers/base/power/opp/opp.h | 1 - 3 files changed, 29 insertions(+), 89 deletions(-) diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index 1a38b5d8dc54..ab9499e3ba02 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -863,27 +863,6 @@ static struct opp_table *_allocate_opp_table(struct device *dev) } /** - * _add_opp_table() - Find OPP table or allocate a new one - * @dev: device for which we do this operation - * - * It tries to find an existing table first, if it couldn't find one, it - * allocates a new OPP table and returns that. - * - * Return: valid opp_table pointer if success, else NULL. - */ -struct opp_table *_add_opp_table(struct device *dev) -{ - struct opp_table *opp_table; - - /* Check for existing table for 'dev' first */ - opp_table = _find_opp_table(dev); - if (!IS_ERR(opp_table)) - return opp_table; - - return _allocate_opp_table(dev); -} - -/** * _kfree_device_rcu() - Free opp_table RCU handler * @head: RCU head */ @@ -922,7 +901,7 @@ struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_table); -static void _opp_table_kref_release_unlocked(struct kref *kref) +static void _opp_table_kref_release(struct kref *kref) { struct opp_table *opp_table = container_of(kref, struct opp_table, kref); struct opp_device *opp_dev; @@ -943,16 +922,7 @@ static void _opp_table_kref_release_unlocked(struct kref *kref) list_del_rcu(&opp_table->node); call_srcu(&opp_table->srcu_head.srcu, &opp_table->rcu_head, _kfree_device_rcu); -} -static void dev_pm_opp_put_opp_table_unlocked(struct opp_table *opp_table) -{ - kref_put(&opp_table->kref, _opp_table_kref_release_unlocked); -} - -static void _opp_table_kref_release(struct kref *kref) -{ - _opp_table_kref_release_unlocked(kref); mutex_unlock(&opp_table_lock); } @@ -963,17 +933,6 @@ void dev_pm_opp_put_opp_table(struct opp_table *opp_table) } EXPORT_SYMBOL_GPL(dev_pm_opp_put_opp_table); -/** - * _remove_opp_table() - Removes a OPP table - * @opp_table: OPP table to be removed. - * - * Removes/frees OPP table if it doesn't contain any OPPs. - */ -static void _remove_opp_table(struct opp_table *opp_table) -{ - dev_pm_opp_put_opp_table_unlocked(opp_table); -} - void _opp_free(struct dev_pm_opp *opp) { kfree(opp); @@ -1218,8 +1177,6 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long tol; int ret; - opp_rcu_lockdep_assert(); - new_opp = _opp_allocate(opp_table); if (!new_opp) return -ENOMEM; @@ -1640,21 +1597,13 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) struct opp_table *opp_table; int ret; - /* Hold our table modification lock here */ - mutex_lock(&opp_table_lock); - - opp_table = _add_opp_table(dev); - if (!opp_table) { - ret = -ENOMEM; - goto unlock; - } + opp_table = dev_pm_opp_get_opp_table(dev); + if (!opp_table) + return -ENOMEM; ret = _opp_add_v1(opp_table, dev, freq, u_volt, true); - if (ret) - _remove_opp_table(opp_table); -unlock: - mutex_unlock(&opp_table_lock); + dev_pm_opp_put_opp_table(opp_table); return ret; } EXPORT_SYMBOL_GPL(dev_pm_opp_add); @@ -1865,8 +1814,6 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, { struct dev_pm_opp *opp, *tmp; - opp_rcu_lockdep_assert(); - /* Find if opp_table manages a single device */ if (list_is_singular(&opp_table->dev_list)) { /* Free static OPPs */ diff --git a/drivers/base/power/opp/of.c b/drivers/base/power/opp/of.c index cdbf733ac9b1..6a6e6e7846b3 100644 --- a/drivers/base/power/opp/of.c +++ b/drivers/base/power/opp/of.c @@ -24,7 +24,9 @@ static struct opp_table *_managed_opp(const struct device_node *np) { - struct opp_table *opp_table; + struct opp_table *opp_table, *managed_table = NULL; + + mutex_lock(&opp_table_lock); list_for_each_entry_rcu(opp_table, &opp_tables, node) { if (opp_table->np == np) { @@ -35,14 +37,18 @@ static struct opp_table *_managed_opp(const struct device_node *np) * But the OPPs will be considered as shared only if the * OPP table contains a "opp-shared" property. */ - if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) - return opp_table; + if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) { + _get_opp_table_kref(opp_table); + managed_table = opp_table; + } - return NULL; + break; } } - return NULL; + mutex_unlock(&opp_table_lock); + + return managed_table; } void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) @@ -368,21 +374,17 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) struct opp_table *opp_table; int ret = 0, count = 0; - mutex_lock(&opp_table_lock); - opp_table = _managed_opp(opp_np); if (opp_table) { /* OPPs are already managed */ if (!_add_opp_dev(dev, opp_table)) ret = -ENOMEM; - goto unlock; + goto put_opp_table; } - opp_table = _add_opp_table(dev); - if (!opp_table) { - ret = -ENOMEM; - goto unlock; - } + opp_table = dev_pm_opp_get_opp_table(dev); + if (!opp_table) + return -ENOMEM; /* We have opp-table node now, iterate over it and add OPPs */ for_each_available_child_of_node(opp_np, np) { @@ -392,14 +394,15 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) if (ret) { dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, ret); - goto free_table; + _dev_pm_opp_remove_table(opp_table, dev, false); + goto put_opp_table; } } /* There should be one of more OPP defined */ if (WARN_ON(!count)) { ret = -ENOENT; - goto free_table; + goto put_opp_table; } opp_table->np = opp_np; @@ -408,12 +411,8 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) else opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE; - goto unlock; - -free_table: - _dev_pm_opp_remove_table(opp_table, dev, false); -unlock: - mutex_unlock(&opp_table_lock); +put_opp_table: + dev_pm_opp_put_opp_table(opp_table); return ret; } @@ -442,13 +441,9 @@ static int _of_add_opp_table_v1(struct device *dev) return -EINVAL; } - mutex_lock(&opp_table_lock); - - opp_table = _add_opp_table(dev); - if (!opp_table) { - ret = -ENOMEM; - goto unlock; - } + opp_table = dev_pm_opp_get_opp_table(dev); + if (!opp_table) + return -ENOMEM; val = prop->value; while (nr) { @@ -465,8 +460,7 @@ static int _of_add_opp_table_v1(struct device *dev) nr -= 2; } -unlock: - mutex_unlock(&opp_table_lock); + dev_pm_opp_put_opp_table(opp_table); return ret; } diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index aae4d8f480ef..a01724363347 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -196,7 +196,6 @@ struct opp_table { /* Routines internal to opp core */ void _get_opp_table_kref(struct opp_table *opp_table); struct opp_table *_find_opp_table(struct device *dev); -struct opp_table *_add_opp_table(struct device *dev); struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table); void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, bool remove_all); void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all);