From patchwork Tue May 20 14:17:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 30467 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f200.google.com (mail-yk0-f200.google.com [209.85.160.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9FA94202FE for ; Tue, 20 May 2014 14:17:35 +0000 (UTC) Received: by mail-yk0-f200.google.com with SMTP id q9sf1094960ykb.7 for ; Tue, 20 May 2014 07:17:34 -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=BmtzDWlM+iFjGjEuplVqZigqZLhSGsQf/L8O903AjmA=; b=IrQU9L5Al/l7YuPs+JPmnb0k1YJ6R+pC5fwEgbp57j3K3dbu3FaGcMtMJD4b+hXG3S RxPTUtMKFa6T/3bzPDGtw8DZ0U6zuQdFz5SxKs+lwVAtjBacsaF3tn0ygyaN9IyQq3Gl wTHPPobLf1NoyKMY2g6krrySc4WUWzEOTXgQaXv4YPXtYIJIdHVi3Tm/sZWY2hK6i7bF m6cv375NNTQYu9wD2RqINVZtvvnoBra1sszEAyOYUWuOJlceQXMfdfz3bC92qh6si9CV BoxCwAzIB4h+F8dxQcum83QCUhzmyxaWfkzqmArKAFEbDTRAWGVNhdqQNB/vdrrJvsWx W9MQ== X-Gm-Message-State: ALoCoQkUcjteL076OVo4nR0U8gFTDnce06IbIs046ZN3YjdwZAgZLIPxHhCASxEPKttjw/PxZb2z X-Received: by 10.52.2.129 with SMTP id 1mr16574532vdu.4.1400595454943; Tue, 20 May 2014 07:17:34 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.31.33 with SMTP id e30ls275461qge.89.gmail; Tue, 20 May 2014 07:17:34 -0700 (PDT) X-Received: by 10.52.227.138 with SMTP id sa10mr3422280vdc.25.1400595454792; Tue, 20 May 2014 07:17:34 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id o2si5012996vew.169.2014.05.20.07.17.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 May 2014 07:17:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.172 as permitted sender) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id oz11so671713veb.17 for ; Tue, 20 May 2014 07:17:34 -0700 (PDT) X-Received: by 10.52.2.229 with SMTP id 5mr3427651vdx.24.1400595454688; Tue, 20 May 2014 07:17:34 -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 ib8csp34407vcb; Tue, 20 May 2014 07:17:34 -0700 (PDT) X-Received: by 10.66.180.168 with SMTP id dp8mr51840701pac.100.1400595453809; Tue, 20 May 2014 07:17:33 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rm10si24820819pab.197.2014.05.20.07.17.33; Tue, 20 May 2014 07:17:33 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-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 S1753768AbaETORY (ORCPT + 27 others); Tue, 20 May 2014 10:17:24 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:64546 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752406AbaETORX (ORCPT ); Tue, 20 May 2014 10:17:23 -0400 Received: by mail-wi0-f179.google.com with SMTP id bs8so1032551wib.6 for ; Tue, 20 May 2014 07:17:22 -0700 (PDT) X-Received: by 10.195.13.76 with SMTP id ew12mr2584400wjd.80.1400595441836; Tue, 20 May 2014 07:17:21 -0700 (PDT) Received: from localhost ([213.122.173.131]) by mx.google.com with ESMTPSA id xn14sm9596283wib.6.2014.05.20.07.17.16 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 20 May 2014 07:17:20 -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 V4] PM/OPP: discard duplicate OPPs Date: Tue, 20 May 2014 19:47:05 +0530 Message-Id: X-Mailer: git-send-email 2.0.0.rc2 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@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.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: , 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 --- V3->V4: - handle duplicate OPPs more appropriately - update comment over routine and enhance commit log @Chander: I have kept your authorship as is, hope you don't mind me sending it on your behalf :) drivers/base/power/opp.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index 2553867..cd9af42 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -389,6 +389,11 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); * The opp is made available by default and it can be controlled using * dev_pm_opp_enable/disable functions. * + * Duplicate OPPs are discarded. Will return 0 if new OPP was duplicate of + * existing one (i.e. same freq and volt) and -EEXIST would be returned if new + * OPP had same freq but different volt as of an existing OPP OR if both were + * same but earlier OPP was disabled. + * * Locking: The internal device_opp and opp structures are RCU protected. * Hence this function internally uses RCU updater strategy with mutex locks * to keep the integrity of the internal data structures. Callers should ensure @@ -443,15 +448,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; + + pr_warn("%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);