From patchwork Thu May 22 05:06:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 30556 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f197.google.com (mail-yk0-f197.google.com [209.85.160.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7FF4220675 for ; Thu, 22 May 2014 05:06:47 +0000 (UTC) Received: by mail-yk0-f197.google.com with SMTP id 19sf6433304ykq.8 for ; Wed, 21 May 2014 22:06:47 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=9JS6HiXRXeo0hFhqCQjWxTjtsPGdwU1rVChi9GMbDcE=; b=e+zQRn6mclAyDOsiHglCxcqSRtSJD1vQ7zvkohPJ4yqrf4EE7Qi9CMg9+r3gyj7EUY qomoadSNoH+ckU/QVFMZJW96FaGF5UQF9DqeDsvt26Axg4clpSR8ywZUWLiCAvrBA7V3 UJX1KLxSAiDShPLsUdp5e7h77cMx/AzY47XLpkzbOyAVdhUiyr+IjALg38N3B6dVP8Q4 bLXRz8eEfjZa+hk8GCEZm0ZgslnzvprsVzXKmP2Bkzph4W8NO9UXhZp0oUu/NVFdTzuV IfIW9pVlpaNS2PiE/jZnOSoagZ795xfkPF9oDir3QuzjgyDoUFubF8d2abXEoX/6wvjX /Dqg== X-Gm-Message-State: ALoCoQnLM9Db004LzLO2B1gYcG+wmnpcWnk3K7eBU/8QSIVjCC/Ziyw5w4YMxLpw9JNVdeTIlfov X-Received: by 10.236.178.98 with SMTP id e62mr8248058yhm.50.1400735207064; Wed, 21 May 2014 22:06:47 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.203 with SMTP id v69ls1111464qgd.6.gmail; Wed, 21 May 2014 22:06:47 -0700 (PDT) X-Received: by 10.52.94.47 with SMTP id cz15mr6013341vdb.0.1400735199598; Wed, 21 May 2014 22:06:39 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id tx9si4249606vcb.102.2014.05.21.22.06.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 21 May 2014 22:06:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.169 as permitted sender) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id jx11so3804576veb.0 for ; Wed, 21 May 2014 22:06:39 -0700 (PDT) X-Received: by 10.58.46.231 with SMTP id y7mr1645594vem.5.1400735199467; Wed, 21 May 2014 22:06:39 -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.220.221.72 with SMTP id ib8csp168128vcb; Wed, 21 May 2014 22:06:38 -0700 (PDT) X-Received: by 10.67.23.135 with SMTP id ia7mr64408419pad.5.1400735198191; Wed, 21 May 2014 22:06:38 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ff3si8986703pbd.167.2014.05.21.22.06.37; Wed, 21 May 2014 22:06:37 -0700 (PDT) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751196AbaEVFGg (ORCPT + 12 others); Thu, 22 May 2014 01:06:36 -0400 Received: from mail-qg0-f51.google.com ([209.85.192.51]:37440 "EHLO mail-qg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751093AbaEVFGf (ORCPT ); Thu, 22 May 2014 01:06:35 -0400 Received: by mail-qg0-f51.google.com with SMTP id q107so4803555qgd.38 for ; Wed, 21 May 2014 22:06:35 -0700 (PDT) X-Received: by 10.224.103.129 with SMTP id k1mr74984695qao.62.1400735195224; Wed, 21 May 2014 22:06:35 -0700 (PDT) Received: from localhost (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id p95sm2068564qgd.23.2014.05.21.22.06.29 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 21 May 2014 22:06:34 -0700 (PDT) From: Viresh Kumar To: rjw@rjwysocki.net Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, arvind.chauhan@arm.com, inderpal.s@samsung.com, nm@ti.com, chander.kashyap@linaro.org, pavel@ucw.cz, len.brown@intel.com, sudeep.holla@arm.com, Chander Kashyap , Viresh Kumar Subject: [PATCH V6] PM/OPP: discard duplicate OPPs Date: Thu, 22 May 2014 10:36:26 +0530 Message-Id: <087f56979fa572b3021f0fb9b2ad1bc791b55f66.1400734949.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.0.0.rc2 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.128.169 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: , From: Chander Kashyap We don't have any protection against addition of duplicate OPPs currently and in case some code tries to add them, it will end up corrupting OPP tables. We need to handle some duplication cases separately as returning error might not be the right thing always. The new list of return values for dev_pm_opp_add() are: 0: On success OR Duplicate OPPs (both freq and volt are same) and opp->available -EEXIST: Freq are same and volt are different OR Duplicate OPPs (both freq and volt are same) and !opp->available -ENOMEM: Memory allocation failure Acked-by: Nishanth Menon Signed-off-by: Chander Kashyap Signed-off-by: Inderpal Singh Signed-off-by: Viresh Kumar --- I took some rest before sending V6, just to make sure I don't send another version in hurry with any obvious mistake. V5->V6: - Remove parenthesis around initialization of 'ret'. - s/Returns/Return - Fix checkpatch.pl --strict warning: 'Alignment should match open parenthesis' - Tried improving changelog.. drivers/base/power/opp.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index faae9cf..89ced95 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -393,6 +393,13 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); * to keep the integrity of the internal data structures. Callers should ensure * that this function is *NOT* called under RCU protection or in contexts where * mutex cannot be locked. + * + * Return: + * 0: On success OR + * Duplicate OPPs (both freq and volt are same) and opp->available + * -EEXIST: Freq are same and volt are different OR + * Duplicate OPPs (both freq and volt are same) and !opp->available + * -ENOMEM: Memory allocation failure */ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) { @@ -442,15 +449,31 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) new_opp->u_volt = u_volt; new_opp->available = true; - /* Insert new OPP in order of increasing frequency */ + /* + * Insert new OPP in order of increasing frequency + * and discard if already present + */ head = &dev_opp->opp_list; list_for_each_entry_rcu(opp, &dev_opp->opp_list, node) { - if (new_opp->rate < opp->rate) + if (new_opp->rate <= opp->rate) break; else head = &opp->node; } + /* Duplicate OPPs ? */ + if (new_opp->rate == opp->rate) { + int 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); + mutex_unlock(&dev_opp_list_lock); + kfree(new_opp); + return ret; + } + list_add_rcu(&new_opp->node, head); mutex_unlock(&dev_opp_list_lock);