From patchwork Mon Jun 15 11:57:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 49850 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 4B499205DE for ; Mon, 15 Jun 2015 11:58:14 +0000 (UTC) Received: by wgbhy7 with SMTP id hy7sf11586328wgb.3 for ; Mon, 15 Jun 2015 04:58:12 -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:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=vVlcGKqxiE9CW/GAaFmfbJTpo9o8tU1BEQ+baZuRQlE=; b=b3u6a+FzC4S1IeLpWA1Wm/V2L/LYzyZFheY93vMht5siepbvkwJDXQT1sBBpRnuCDj /dwvbcYVqNoHWCFjYdFlDILj9/KZInqPUVDDDmzPUY091/1GXj4QEK4jNSSzSINiuE1l L26VzA6wvlqtB9YcWpRZjmDbyCy2p/Wocv2dKRRvdV6CJgF4c5o113dpE/nZ3I2u1Qyb EHE76ZyTKYWheBLhFMOU6a9AtDVy6FG0d3N+qFo2NIisTJHoMNGrAoJNfD+njpCEnsSC VVMAiCe81QIkSQ+HGJKpC8eZGAHOmY5RWuVaoPLuhZJ0eeLP45jQDUviJbUUKcBqLS/U b+aw== X-Gm-Message-State: ALoCoQlX1zA1cicdAjml/xBYVTzLXdjOLz8tHPuzQf855AyzImDkU4gQgCBb18/57hUHzg6Lo9DN X-Received: by 10.152.219.166 with SMTP id pp6mr29500905lac.1.1434369492277; Mon, 15 Jun 2015 04:58:12 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.101 with SMTP id p5ls965808laj.53.gmail; Mon, 15 Jun 2015 04:58:12 -0700 (PDT) X-Received: by 10.152.36.65 with SMTP id o1mr27379878laj.55.1434369492127; Mon, 15 Jun 2015 04:58:12 -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 wm3si10277602lac.177.2015.06.15.04.58.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2015 04:58:12 -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 labbc20 with SMTP id bc20so19915286lab.1 for ; Mon, 15 Jun 2015 04:58:12 -0700 (PDT) X-Received: by 10.112.234.200 with SMTP id ug8mr26426890lbc.117.1434369492016; Mon, 15 Jun 2015 04:58:12 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1363564lbb; Mon, 15 Jun 2015 04:58:10 -0700 (PDT) X-Received: by 10.70.5.101 with SMTP id r5mr47837260pdr.139.1434369490138; Mon, 15 Jun 2015 04:58:10 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gu10si258184pbc.26.2015.06.15.04.58.09; Mon, 15 Jun 2015 04:58:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753966AbbFOL6I (ORCPT + 11 others); Mon, 15 Jun 2015 07:58:08 -0400 Received: from mail-pd0-f169.google.com ([209.85.192.169]:35450 "EHLO mail-pd0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753329AbbFOL6H (ORCPT ); Mon, 15 Jun 2015 07:58:07 -0400 Received: by pdbnf5 with SMTP id nf5so71734512pdb.2 for ; Mon, 15 Jun 2015 04:58:07 -0700 (PDT) X-Received: by 10.68.224.10 with SMTP id qy10mr48588045pbc.23.1434369487216; Mon, 15 Jun 2015 04:58:07 -0700 (PDT) Received: from localhost ([122.167.70.98]) by mx.google.com with ESMTPSA id v5sm12054088pdo.29.2015.06.15.04.58.06 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 15 Jun 2015 04:58:06 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , rob.herring@linaro.org, nm@ti.com Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, arnd.bergmann@linaro.org, broonie@kernel.org, mike.turquette@linaro.org, sboyd@codeaurora.org, Sudeep.Holla@arm.com, viswanath.puttagunta@linaro.org, l.stach@pengutronix.de, thomas.petazzoni@free-electrons.com, linux-arm-kernel@lists.infradead.org, ta.omasab@gmail.com, kesavan.abhilash@gmail.com, khilman@linaro.org, santosh.shilimkar@oracle.com, Viresh Kumar Subject: [PATCH 03/10] OPP: Allocate dev_opp from _add_device_opp() Date: Mon, 15 Jun 2015 17:27:29 +0530 Message-Id: <83bd3b9837b30bab62f41aed3dd2cdf52cc21688.1434369079.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , There is no need to complicate _opp_add_dynamic() with allocation of dev_opp as well. Allocate it from _add_device_opp() instead. Signed-off-by: Viresh Kumar --- drivers/base/power/opp.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 7895fdd64192..4b646f36f252 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -408,11 +408,11 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); /** - * _add_device_opp() - Allocate a new device OPP table + * _add_device_opp() - Returns device OPP table * @dev: device for which we do this operation * - * New device node which uses OPPs - used when multiple devices with OPP tables - * are maintained. + * 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 device_opp pointer if success, else NULL. */ @@ -420,6 +420,11 @@ static struct device_opp *_add_device_opp(struct device *dev) { struct device_opp *dev_opp; + /* Check for existing list for 'dev' first */ + dev_opp = _find_device_opp(dev); + if (!IS_ERR(dev_opp)) + return dev_opp; + /* * Allocate a new device OPP table. In the infrequent case where a new * device is needed to be added, we pay this penalty. @@ -575,8 +580,8 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_remove); static int _opp_add_dynamic(struct device *dev, unsigned long freq, long u_volt, bool dynamic) { - struct device_opp *dev_opp = NULL; - struct dev_pm_opp *opp, *new_opp; + struct device_opp *dev_opp; + struct dev_pm_opp *opp = NULL, *new_opp; struct list_head *head; int ret; @@ -592,19 +597,11 @@ static int _opp_add_dynamic(struct device *dev, unsigned long freq, new_opp->rate = freq; new_opp->u_volt = u_volt; new_opp->available = true; - new_opp->dynamic = dynamic; - /* Check for existing list for 'dev' */ - dev_opp = _find_device_opp(dev); - if (IS_ERR(dev_opp)) { - dev_opp = _add_device_opp(dev); - if (!dev_opp) { - ret = -ENOMEM; - goto free_opp; - } - - head = &dev_opp->opp_list; - goto list_add; + dev_opp = _add_device_opp(dev); + if (!dev_opp) { + ret = -ENOMEM; + goto free_opp; } /* @@ -620,17 +617,17 @@ static int _opp_add_dynamic(struct device *dev, unsigned long freq, } /* Duplicate OPPs ? */ - if (new_opp->rate == opp->rate) { + if (opp && new_opp->rate == opp->rate) { ret = opp->available && new_opp->u_volt == opp->u_volt ? 0 : -EEXIST; dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n", __func__, opp->rate, opp->u_volt, opp->available, new_opp->rate, new_opp->u_volt, new_opp->available); - goto free_opp; + goto remove_dev_opp; } -list_add: + new_opp->dynamic = dynamic; new_opp->dev_opp = dev_opp; list_add_rcu(&new_opp->node, head); mutex_unlock(&dev_opp_list_lock); @@ -642,6 +639,8 @@ static int _opp_add_dynamic(struct device *dev, unsigned long freq, srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_ADD, new_opp); return 0; +remove_dev_opp: + _remove_device_opp(dev_opp); free_opp: mutex_unlock(&dev_opp_list_lock); kfree(new_opp);