From patchwork Mon Jan 2 09:11:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 9493209 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 7E5BC60414 for ; Mon, 2 Jan 2017 09:12:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67D6A2015F for ; Mon, 2 Jan 2017 09:12:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B5F326861; Mon, 2 Jan 2017 09:12:17 +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 DE1AA2015F for ; Mon, 2 Jan 2017 09:12:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932521AbdABJLt (ORCPT ); Mon, 2 Jan 2017 04:11:49 -0500 Received: from mail-pf0-f174.google.com ([209.85.192.174]:36429 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932519AbdABJLr (ORCPT ); Mon, 2 Jan 2017 04:11:47 -0500 Received: by mail-pf0-f174.google.com with SMTP id 189so72554013pfz.3 for ; Mon, 02 Jan 2017 01:11:47 -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=QWDdPHM2iucXBs3oo8G5AtWUZvhyVnjy9RPS8shpOGk=; b=FYzI8K64lFuQBA/f/JKlIDYUj5Kxps8xtCGywF5NLv3zhVEy0fU4urZxk7AIxuCaVQ KojIoWo4CIeSCpQaWu3Yh5V2Px+tEK8OKoRx6nrYkXAvKrF8IwxKQWR0+91tsFdzfKvs l9sBqmu3y5qXhYo+EgJ/FM/1LZtDKzRtIPBQQ= 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=QWDdPHM2iucXBs3oo8G5AtWUZvhyVnjy9RPS8shpOGk=; b=Fal7OMdSdlrsjfNUgWy4eGksd46YXb48+2M19C+/GirgTOY5zyIVcTkRAB834DudlQ LhV8kzNx2Uo2tFjvP+SOpCejMc8hDXMGzsv5/43NyEuxAxbNR2rBnKLAdfMBZ0uHhlSO jApw/WOovzSL1KN47TmEQEGhm7PIbo0IaHxpxpkY2XWJqF9fpbqlKoPXYrN9XkekosWw arIoxYWsXN3o4DRuG/9rzXQKoJpPuUoV0KIF3/Vh7piebSDVq/gdYAxvQthBFI5xU5MX eOSNFZQvHhptrVaE/zqlOEsMzuNRIjBZ0qp9j6qOr01Ae4nMh972Q6CgjJNFVuFVnF+0 nkzg== X-Gm-Message-State: AIkVDXLyreP2juMDgiLO0oyueCnT6mPj6bveQ4AqMBf51JoYrL9Ic05Grr/3Jh4eL89ta+jv X-Received: by 10.84.209.204 with SMTP id y70mr114821817plh.180.1483348306783; Mon, 02 Jan 2017 01:11:46 -0800 (PST) Received: from localhost ([122.172.43.83]) by smtp.gmail.com with ESMTPSA id g82sm130355675pfb.43.2017.01.02.01.11.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jan 2017 01:11:46 -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 V3 10/10] PM / OPP: Split out part of _add_opp_table() and _remove_opp_table() Date: Mon, 2 Jan 2017 14:41:04 +0530 Message-Id: <7d4e1b547d5a5e0519edf42cbb2e9ce6e609a901.1483348138.git.viresh.kumar@linaro.org> 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 Split out parts of _add_opp_table() and _remove_opp_table() into separate routines. This improves readability as well. Should result in no functional changes. Signed-off-by: Viresh Kumar Reviewed-by: Stephen Boyd --- drivers/base/power/opp/core.c | 76 +++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index f35effad60d1..622dd32f8dda 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -819,26 +819,12 @@ struct opp_device *_add_opp_dev(const struct device *dev, return opp_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) +static struct opp_table *_allocate_opp_table(struct device *dev) { struct opp_table *opp_table; struct opp_device *opp_dev; int ret; - /* Check for existing table for 'dev' first */ - opp_table = _find_opp_table(dev); - if (!IS_ERR(opp_table)) - return opp_table; - /* * Allocate a new OPP table. In the infrequent case where a new * device is needed to be added, we pay this penalty. @@ -875,6 +861,27 @@ struct opp_table *_add_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 */ @@ -886,6 +893,27 @@ static void _kfree_device_rcu(struct rcu_head *head) kfree_rcu(opp_table, rcu_head); } +static void _free_opp_table(struct opp_table *opp_table) +{ + struct opp_device *opp_dev; + + /* Release clk */ + if (!IS_ERR(opp_table->clk)) + clk_put(opp_table->clk); + + opp_dev = list_first_entry(&opp_table->dev_list, struct opp_device, + node); + + _remove_opp_dev(opp_dev, opp_table); + + /* dev_list must be empty now */ + WARN_ON(!list_empty(&opp_table->dev_list)); + + list_del_rcu(&opp_table->node); + call_srcu(&opp_table->srcu_head.srcu, &opp_table->rcu_head, + _kfree_device_rcu); +} + /** * _remove_opp_table() - Removes a OPP table * @opp_table: OPP table to be removed. @@ -894,8 +922,6 @@ static void _kfree_device_rcu(struct rcu_head *head) */ static void _remove_opp_table(struct opp_table *opp_table) { - struct opp_device *opp_dev; - if (!list_empty(&opp_table->opp_list)) return; @@ -911,21 +937,7 @@ static void _remove_opp_table(struct opp_table *opp_table) if (opp_table->set_opp) return; - /* Release clk */ - if (!IS_ERR(opp_table->clk)) - clk_put(opp_table->clk); - - opp_dev = list_first_entry(&opp_table->dev_list, struct opp_device, - node); - - _remove_opp_dev(opp_dev, opp_table); - - /* dev_list must be empty now */ - WARN_ON(!list_empty(&opp_table->dev_list)); - - list_del_rcu(&opp_table->node); - call_srcu(&opp_table->srcu_head.srcu, &opp_table->rcu_head, - _kfree_device_rcu); + _free_opp_table(opp_table); } void _opp_free(struct dev_pm_opp *opp)