From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751196AbaETUwx (ORCPT ); Tue, 20 May 2014 16:52:53 -0400 Received: from v094114.home.net.pl ([79.96.170.134]:56482 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751096AbaETUwv (ORCPT ); Tue, 20 May 2014 16:52:51 -0400 From: "Rafael J. Wysocki" To: Viresh Kumar 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 Subject: Re: [PATCH V5] PM/OPP: discard duplicate OPPs Date: Tue, 20 May 2014 23:09:47 +0200 Message-ID: <1555967.8fxByr2j83@vostro.rjw.lan> User-Agent: KMail/4.11.5 (Linux/3.15.0-rc5+; KDE/4.11.5; x86_64; ; ) In-Reply-To: <7cb6e0e039e0935e37c81d0f23d26b0b81ad8cda.1400597170.git.viresh.kumar@linaro.org> References: <7cb6e0e039e0935e37c81d0f23d26b0b81ad8cda.1400597170.git.viresh.kumar@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday, May 20, 2014 08:23:28 PM Viresh Kumar wrote: > 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 > --- > 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; The parens are not necessary. And is the direction correct? > + > + 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); > > -- I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.