From patchwork Mon Jul 27 05:02:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 51484 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id 8073D214B7 for ; Mon, 27 Jul 2015 05:03:45 +0000 (UTC) Received: by lbcjj5 with SMTP id jj5sf23478051lbc.1 for ; Sun, 26 Jul 2015 22:03:44 -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=ZYhhtTKe31SGgD/4Aps2bQ+/ujBHcM0aSGkZxDvJHS0=; b=jCj3I0fwGiTsn0x58JqJiwwvy00LWwr+5iJlxzzRgfswB+ImC0iBWE/oVFCv2soAmV vIJ9AJz+WbGnbweKbwxRx7RQ7JZvqPvRG7m8PbVuiG3q0d1sDb7EHEhqsC8pFyq/m9h7 HCpWP/E4mCRdJpXJmZCYtTFGUea9/Yl8BuHT57FIVnAYDPtO4cwZeHW9x9Ck97kYtw6d zokc/+S/6ZQvUZlsMlUKlqhQxrpn1oy0m2qo01w533NEkpSGt9wVLcWi6Ij0BKTLP1GL FsPnXvLbuBBZca/rSWAmlRxeaSm495k4bb7KcDHWlhD1wCTf+DOnmrd79lAAfrqLpUv6 SgbA== X-Gm-Message-State: ALoCoQnTi2HfnYLKImKda6QolS/Zzzd0fghjzCiUr4VMYs9DlAgC3PWzeJ4MydRj+DGpcwXgyDyr X-Received: by 10.112.28.111 with SMTP id a15mr11267716lbh.21.1437973424476; Sun, 26 Jul 2015 22:03:44 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.195 with SMTP id o3ls628666laf.1.gmail; Sun, 26 Jul 2015 22:03:44 -0700 (PDT) X-Received: by 10.152.43.16 with SMTP id s16mr25119569lal.101.1437973424327; Sun, 26 Jul 2015 22:03:44 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id v2si14368953lbk.22.2015.07.26.22.03.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 22:03:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by lafd3 with SMTP id d3so31533130laf.1 for ; Sun, 26 Jul 2015 22:03:43 -0700 (PDT) X-Received: by 10.152.36.102 with SMTP id p6mr25250503laj.19.1437973423880; Sun, 26 Jul 2015 22:03:43 -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.7.198 with SMTP id l6csp1314716lba; Sun, 26 Jul 2015 22:03:42 -0700 (PDT) X-Received: by 10.107.132.15 with SMTP id g15mr37904096iod.134.1437973421770; Sun, 26 Jul 2015 22:03:41 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fb10si24692574pdb.169.2015.07.26.22.03.40; Sun, 26 Jul 2015 22:03:41 -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 S1750723AbbG0FDj (ORCPT + 12 others); Mon, 27 Jul 2015 01:03:39 -0400 Received: from mail-pd0-f170.google.com ([209.85.192.170]:34741 "EHLO mail-pd0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750955AbbG0FDf (ORCPT ); Mon, 27 Jul 2015 01:03:35 -0400 Received: by pdbbh15 with SMTP id bh15so45260408pdb.1 for ; Sun, 26 Jul 2015 22:03:35 -0700 (PDT) X-Received: by 10.70.90.42 with SMTP id bt10mr63585378pdb.60.1437973415054; Sun, 26 Jul 2015 22:03:35 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id fy5sm26753079pdb.93.2015.07.26.22.03.33 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 26 Jul 2015 22:03:34 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, rob.herring@linaro.org, arnd.bergmann@linaro.org, nm@ti.com, broonie@kernel.org, mturquette@baylibre.com, 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, b.zolnierkie@samsung.com, Viresh Kumar , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Pavel Machek Subject: [PATCH V2 04/11] OPP: Allocate dev_opp from _add_device_opp() Date: Mon, 27 Jul 2015 10:32:34 +0530 Message-Id: <1b6eba9446126e95d06bce73596d24bbdc14505e.1437972635.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.43 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. Reviewed-by: Stephen Boyd Reviewed-by: Bartlomiej Zolnierkiewicz Signed-off-by: Viresh Kumar --- drivers/base/power/opp.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 7895fdd64192..901b6c77a791 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() - Find device OPP table or allocate a new one * @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,7 +580,7 @@ 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 device_opp *dev_opp; struct dev_pm_opp *opp, *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; } /* @@ -613,14 +610,12 @@ static int _opp_add_dynamic(struct device *dev, unsigned long freq, */ head = &dev_opp->opp_list; list_for_each_entry_rcu(opp, &dev_opp->opp_list, node) { - if (new_opp->rate <= opp->rate) - break; - else + if (new_opp->rate > opp->rate) head = &opp->node; - } + else if (new_opp->rate < opp->rate) + break; - /* Duplicate OPPs ? */ - if (new_opp->rate == opp->rate) { + /* Duplicate OPPs */ ret = opp->available && new_opp->u_volt == opp->u_volt ? 0 : -EEXIST; @@ -630,7 +625,7 @@ static int _opp_add_dynamic(struct device *dev, unsigned long freq, goto free_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);