From patchwork Tue May 20 14:53:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 30475 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2F27E20671 for ; Tue, 20 May 2014 14:54:00 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id wo20sf2263788obc.11 for ; Tue, 20 May 2014 07:53:59 -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=MxDz7WTPFwfL0Uhq6la9W2H5cApv4TRpK20vj+1RAxw=; b=eP58JvXP7nq5FLOLTQjquX4HvOV5+U+Ck448rYwTFlhHAXYPHss1EM1+gQbc3d3RIL Q+FjPCzQJQ6gsr0ROHeE3xaNwWl6PaXR+QfKWS6dnt2dcjPL1XhXbuElBxwY06RecqQo n3nOFg5qzN7EZQvbMYDVFcloMER2rylztSBEBAfyNbUnu7H7ly/H0g0VWT3SoE7qfpVn C9QBjD6Dcn38xtgL1PthZfAlDshpB8z5hNwqBuNRmPkFwyBkJmp2xcmsMmnjofju6Oc0 nZtQ9Qs7ttYn6BuvWOQLmzgOMq3Coweh7YVQJ/0P6DLdTtiBLPxfoBbs5YXpTgotsv2a Xzhw== X-Gm-Message-State: ALoCoQn1Ky+Jsw4W0M62zB4h39W0iND++5gXBxNKEye2KGY2kl9CAVsLBmB8Ue139MBVR6SkLvJm X-Received: by 10.182.210.137 with SMTP id mu9mr3325607obc.48.1400597639793; Tue, 20 May 2014 07:53:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.43.135 with SMTP id e7ls324622qga.70.gmail; Tue, 20 May 2014 07:53:59 -0700 (PDT) X-Received: by 10.58.187.165 with SMTP id ft5mr1426873vec.47.1400597639600; Tue, 20 May 2014 07:53:59 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id ui2si5034001vdc.100.2014.05.20.07.53.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 May 2014 07:53:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id ld13so739871vcb.40 for ; Tue, 20 May 2014 07:53:59 -0700 (PDT) X-Received: by 10.221.7.71 with SMTP id on7mr4226205vcb.18.1400597639524; Tue, 20 May 2014 07:53:59 -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 ib8csp37139vcb; Tue, 20 May 2014 07:53:59 -0700 (PDT) X-Received: by 10.68.201.226 with SMTP id kd2mr50994313pbc.157.1400597638764; Tue, 20 May 2014 07:53:58 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id le9si24945325pab.198.2014.05.20.07.53.58; Tue, 20 May 2014 07:53:58 -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 S1753846AbaETOxm (ORCPT + 12 others); Tue, 20 May 2014 10:53:42 -0400 Received: from mail-wg0-f47.google.com ([74.125.82.47]:50514 "EHLO mail-wg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753766AbaETOxl (ORCPT ); Tue, 20 May 2014 10:53:41 -0400 Received: by mail-wg0-f47.google.com with SMTP id x12so614175wgg.18 for ; Tue, 20 May 2014 07:53:39 -0700 (PDT) X-Received: by 10.194.6.106 with SMTP id z10mr36996775wjz.1.1400597619501; Tue, 20 May 2014 07:53:39 -0700 (PDT) Received: from localhost ([213.122.173.131]) by mx.google.com with ESMTPSA id ed6sm21130988wib.20.2014.05.20.07.53.33 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 20 May 2014 07:53:38 -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, Chander Kashyap , Viresh Kumar Subject: [PATCH V5] PM/OPP: discard duplicate OPPs Date: Tue, 20 May 2014 20:23:28 +0530 Message-Id: <7cb6e0e039e0935e37c81d0f23d26b0b81ad8cda.1400597170.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.220.181 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. There can be many combinations in which we may end up trying duplicate OPPs: - both freq and volt are same, but earlier OPP may or may not be active. - only freq is same and volt is different. This patch tries to implement below logic for these cases: Return 0 if new OPP was duplicate of existing one (i.e. same freq and volt) and return -EEXIST if new OPP had same freq but different volt as of an existing OPP OR if both freq/volt were same but earlier OPP was disabled. Signed-off-by: Chander Kashyap Signed-off-by: Inderpal Singh Signed-off-by: Viresh Kumar Acked-by: Nishanth Menon --- V4->V5: - Mention Return values under 'Return:' clause of doc style comment. - s/pr_warn/dev_warn - s/linrao/linaro in my email id :( 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 2553867..6a06d43 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -394,6 +394,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. + * + * Returns: + * 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) { @@ -443,15 +450,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 = (new_opp->u_volt == opp->u_volt) && opp->available ? + 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);