From patchwork Fri Jul 3 06:45:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 50609 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 07933218E1 for ; Fri, 3 Jul 2015 06:46:10 +0000 (UTC) Received: by lagh6 with SMTP id h6sf25420981lag.0 for ; Thu, 02 Jul 2015 23:46:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=7ViOywHYvNlH45Io8Izkyeg5ouNO1zpi+V+GlBXex3k=; b=ZarWzLxVmk6u7FFFvUZsHZ7YVg5bp4LfoG7zOtGUJrItYt8USQBZbseapcMuKnJoCG 0Fqn4NwlfM70xmz4ukEDsJ9ukzgWtcC4oJ1L8IL23krDLQYwkTdfY7OAE9poqrzIiBDZ zFnBwcdn9KIYmBf/WfpjDLCGkSgsFYAj/UpALyyq8hFJH7XmPuIQvjFWEO0jC2QNuhcy CX+pvEjoHadc8imlKJ7CCCB4826/ePecyaYEBgo+MheezibmuxYxPOoAJZqkTIBGhdUR Z8tLen0HPCT4Nr+Y6ZetAlKysJdEUn6YjNAseBzg85/EhYEaC9Hxnb1tnp2Z+gkN9gVb 8UbQ== X-Gm-Message-State: ALoCoQmRwTSc/y6BiFZ9+PWBTwp+UPq52AR+D7w4uW22pXZp6PysqWIA/SgM4u24gdmdQJXH8DZK X-Received: by 10.112.26.5 with SMTP id h5mr22005698lbg.4.1435905969011; Thu, 02 Jul 2015 23:46:09 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.146 with SMTP id j18ls450739laa.22.gmail; Thu, 02 Jul 2015 23:46:08 -0700 (PDT) X-Received: by 10.112.135.131 with SMTP id ps3mr34031989lbb.84.1435905968856; Thu, 02 Jul 2015 23:46:08 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id k13si6432653laa.79.2015.07.02.23.46.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2015 23:46:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbbpo10 with SMTP id po10so44478917lbb.3 for ; Thu, 02 Jul 2015 23:46:08 -0700 (PDT) X-Received: by 10.152.22.99 with SMTP id c3mr35068465laf.32.1435905968693; Thu, 02 Jul 2015 23:46:08 -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 hn6csp950876lbb; Thu, 2 Jul 2015 23:46:07 -0700 (PDT) X-Received: by 10.70.50.199 with SMTP id e7mr74771917pdo.124.1435905966665; Thu, 02 Jul 2015 23:46:06 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ah3si12893727pad.55.2015.07.02.23.46.05; Thu, 02 Jul 2015 23:46:06 -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 S1754499AbbGCGqE (ORCPT + 11 others); Fri, 3 Jul 2015 02:46:04 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:35335 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751621AbbGCGqC (ORCPT ); Fri, 3 Jul 2015 02:46:02 -0400 Received: by pactm7 with SMTP id tm7so52588971pac.2 for ; Thu, 02 Jul 2015 23:46:02 -0700 (PDT) X-Received: by 10.68.179.193 with SMTP id di1mr13206034pbc.55.1435905962143; Thu, 02 Jul 2015 23:46:02 -0700 (PDT) Received: from localhost ([223.227.104.121]) by mx.google.com with ESMTPSA id u7sm7818239pdo.49.2015.07.02.23.45.59 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 02 Jul 2015 23:46:01 -0700 (PDT) Date: Fri, 3 Jul 2015 12:15:54 +0530 From: Viresh Kumar To: Stephen Boyd Cc: Rafael Wysocki , rob.herring@linaro.org, nm@ti.com, linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, arnd.bergmann@linaro.org, broonie@kernel.org, mike.turquette@linaro.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 Subject: Re: [PATCH 03/10] OPP: Allocate dev_opp from _add_device_opp() Message-ID: <20150703064554.GB4564@linux> References: <83bd3b9837b30bab62f41aed3dd2cdf52cc21688.1434369079.git.viresh.kumar@linaro.org> <55948DB0.8060500@codeaurora.org> <20150702062455.GD31684@linux> <5595CD68.9040701@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5595CD68.9040701@codeaurora.org> User-Agent: Mutt/1.5.21 (2010-09-15) 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.217.172 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: , On 02-07-15, 16:46, Stephen Boyd wrote: > Looking better. And does this look perfect ? :) ------------------8<---------------- Message-Id: <7c23b93b6b328e0b14b5c5096c3c3322e3d8ee4b.1435905782.git.viresh.kumar@linaro.org> From: Viresh Kumar Date: Fri, 12 Jun 2015 12:43:14 +0530 Subject: [PATCH] OPP: Allocate dev_opp from _add_device_opp() 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 | 60 +++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 7895fdd64192..5869a8524244 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,24 +610,25 @@ 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; + } else { + /* Duplicate OPPs */ + 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; + } } - /* Duplicate OPPs ? */ - if (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; - } - -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);