From patchwork Wed Dec 7 10:37:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 87019 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp245693qgi; Wed, 7 Dec 2016 02:44:43 -0800 (PST) X-Received: by 10.99.97.15 with SMTP id v15mr120965341pgb.10.1481107483089; Wed, 07 Dec 2016 02:44:43 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s186si23520623pgb.6.2016.12.07.02.44.42; Wed, 07 Dec 2016 02:44:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932441AbcLGKok (ORCPT + 25 others); Wed, 7 Dec 2016 05:44:40 -0500 Received: from mail-pg0-f54.google.com ([74.125.83.54]:33010 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752640AbcLGKmf (ORCPT ); Wed, 7 Dec 2016 05:42:35 -0500 Received: by mail-pg0-f54.google.com with SMTP id 3so160851283pgd.0 for ; Wed, 07 Dec 2016 02:41:50 -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=AoAEia8MC9Pt/HJFXWugoWitOh/aNWIErIdWxNkr10k=; b=FKYz3R9Wk5Z5kDpbrzUdcYMpRl3aIpb/rGzKnlMSyC7ItXvMyWhCNM4yGiBzszLDPW 7qzYtyc2pSz4nGRdQtsYeq3YrZZGZ4861UzrY1he+fO9bCsDmMT+ngfof84+X/ikbgj1 5tFucw9swp5DKIFTt0mSL/nWXyjRoaVMUE9DA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=AoAEia8MC9Pt/HJFXWugoWitOh/aNWIErIdWxNkr10k=; b=cVU70LhaZ8NfYndRdAgcCrGbXJv9ewVvkVsTbvkPWIDt2/bsaFBx9IvJVfjbWPmHu1 7/cYQoVOWCKKaI5BsMHptS1sHpsQxn0Jf16/A3RjuSsFa95qz6u3qcW3mK6G0mqAKQQy Zy1vR+NDw98QFR1IHwqkb55oMkw13pGtrsrjlMlVb5zV7SS9MvVyIvI+OyvGa0zCTVzk v8dQv5i+O+tmMJEp/s5vXcSp3kj/wESEkatyEEsMML2PNHoFYbgS9+MPAfKMnSTy95BW 6klWdV7Wwhvz6CJMxOUuUQ3rT6Y8wQTADxzmlCwOfeMFvCld7I3ShdZzrjgzn4InweBS xR0g== X-Gm-Message-State: AKaTC01B4Qf3rwDp+CO2qq+3lQck2uPZeVRrgfD/OKyg5ZovIB2+Sp4Yq52QgUK/HYniuCLx X-Received: by 10.99.153.26 with SMTP id d26mr121488424pge.44.1481107310105; Wed, 07 Dec 2016 02:41:50 -0800 (PST) Received: from localhost ([122.172.43.83]) by smtp.gmail.com with ESMTPSA id p67sm41613498pfb.2.2016.12.07.02.41.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2016 02:41:49 -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 11/12] PM / OPP: Simplify dev_pm_opp_get_max_volt_latency() Date: Wed, 7 Dec 2016 16:07:49 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dev_pm_opp_get_max_volt_latency() calls _find_opp_table() two times effectively. Merge _get_regulator_count() into dev_pm_opp_get_max_volt_latency() to avoid that. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index 6a1374fafe75..21be3377c135 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -170,22 +170,6 @@ unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_clock_latency); -static int _get_regulator_count(struct device *dev) -{ - struct opp_table *opp_table; - int count; - - opp_table = _find_opp_table(dev); - if (IS_ERR(opp_table)) - return 0; - - count = opp_table->regulator_count; - - dev_pm_opp_put_opp_table(opp_table); - - return count; -} - /** * dev_pm_opp_get_max_volt_latency() - Get max voltage latency in nanoseconds * @dev: device for which we do this operation @@ -204,24 +188,24 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) unsigned long max; } *uV; - count = _get_regulator_count(dev); + opp_table = _find_opp_table(dev); + if (IS_ERR(opp_table)) + return 0; + + count = opp_table->regulator_count; /* Regulator may not be required for the device */ if (!count) - return 0; + goto put_opp_table; regulators = kmalloc_array(count, sizeof(*regulators), GFP_KERNEL); if (!regulators) - return 0; + goto put_opp_table; uV = kmalloc_array(count, sizeof(*uV), GFP_KERNEL); if (!uV) goto free_regulators; - opp_table = _find_opp_table(dev); - if (IS_ERR(opp_table)) - goto free_uV; - memcpy(regulators, opp_table->regulators, count * sizeof(*regulators)); mutex_lock(&opp_table->lock); @@ -242,7 +226,6 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) } mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); /* * The caller needs to ensure that opp_table (and hence the regulator) @@ -254,10 +237,11 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) latency_ns += ret * 1000; } -free_uV: kfree(uV); free_regulators: kfree(regulators); +put_opp_table: + dev_pm_opp_put_opp_table(opp_table); return latency_ns; }