Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4815982pxu; Tue, 22 Dec 2020 01:16:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsxtY8Il5gQ4wSvZfjGwE9ilARHzjT4Ki+tut4lR+E91j9wmTmZlUPFKm0HqYoKjbk364+ X-Received: by 2002:aa7:d2c9:: with SMTP id k9mr19377509edr.74.1608628574778; Tue, 22 Dec 2020 01:16:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608628574; cv=none; d=google.com; s=arc-20160816; b=ex3cWSX6bwNJa9V2opY+VZIHJKLEsELjGWAS6Xd+Zqs/+xGupBU45vMS6KUnB1kvCD BfCiHx5KE+IdDhCTcCSt3G0735UBAfYLY+z7I4Jww/822ua9AOUawzedeCIb5DuCj/9z oBv5OMePN3uMA2olq76N1IslOro4m3YcV2F2EeatxGzFzE8Tua+kfNMC9g0ObJQY1HCN z/pqtpPOB96Ak0kW9hE8uqkCbWgmsGscEA+YQ3sjUDuVzm4rEIkIbsfbE9Owjve7V3Gs 98R9PpCbky9i5HE8OBUiws6XH4H2IzFcTS98ogiA0nahUKZfiCrCDJU3IX0GsqQiJcGc lL2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=aRm1EWTlrTuCGHC7vrOatFzPVY2kkbfTNw0mXXouB3Y=; b=gMUNzb+qOYS7EEJz6ubwGJW0Nripvg4jGfP/BhGuazeNZ64L9C9CKekMoDLlUEMCJC LgF85A5+/c53tHzFWaOx59aky18yF40/q5BROMfksJpyFk0kurzeI37hVPnyoo2UT5kW 12OFTb8CInrnZzeTg/0Lx4EkaxT9XOjN9ku5Q+GI9lM4oYCdqDN2Qmny0AtceSYpEe3X QJlTLRz11UTNWJpDeaBY/E+HxFBlQYwppYwlbWA2peukzw4q+tVBUOXk0rBKirR4O0S3 grZ5LaOuGsk3EPHzN4fDigaKfvOxNpbHXla1617YsBqhNoaBvkwd6BcSOE+ioFZnEDrT MNRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tz4gidYh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si793630ejo.101.2020.12.22.01.15.51; Tue, 22 Dec 2020 01:16:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tz4gidYh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725847AbgLVJNl (ORCPT + 99 others); Tue, 22 Dec 2020 04:13:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725841AbgLVJNj (ORCPT ); Tue, 22 Dec 2020 04:13:39 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E82DC06179C for ; Tue, 22 Dec 2020 01:12:59 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id b5so1017712pjk.2 for ; Tue, 22 Dec 2020 01:12:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=aRm1EWTlrTuCGHC7vrOatFzPVY2kkbfTNw0mXXouB3Y=; b=Tz4gidYhRSQQPvxdsB7tqMzsVoYO3crt2ApaMJh6sBPNnz4QdlfPaFxg6Qw+Q9Ttkt wKFwX+PObpzq/4fdMTp+4B5KTH7Re12uhYrXa3HvCaddYet13JjFo+rTTdsSEt5DlkKf bp6SZO5FTIRmcpzQljrgkAITPVaV0bSdOcJWvfc30sM+iw3nPXkWpPYye4ZZWT5QEdXD faqbA50HRxcmPr6Nr9VSBUdTtKxm6LXMJ4WI1xvuYIbxPBsTtG37wCAzUBTtYOR26zRD K/mV0VlzeObZyhDbSnYISRJfGVOrWvx6nt6WqoFU5TRml3oWxZBdtwp7XRKvKR1Qp9D/ ptAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=aRm1EWTlrTuCGHC7vrOatFzPVY2kkbfTNw0mXXouB3Y=; b=BSWSD4EhY0watgbgexKOFl+FF3BwUbBmd1ZUdNJLxacXxPnidOWI09/c8o1rcMPqaz NCln/MEdm1pwQ1sFOv98wfCC/vAnJyjLQN7W2EhulStLgpvH25JNAidE3c1kZwN2gugv 65w1TLccbRHEiSxS+9w6m8GE5CawIgUK5jParLFKK2no/tVhyaiKMc1WEtQNhoFq0n7x xsFkz5zHJtZEWlJskUEjGbnxugw1TSgA3RJH5q4Asg7hQGnC6W9YsWGTq4Aersif2u31 oPiL4uyrkASqzZrVj5kUdgTz/lgtU/R6nzpWr/j3uWQTTqvD86d+BK0WzgjhzZRO34rg zO8w== X-Gm-Message-State: AOAM530PWVaX+HB1zOM+L93iavnGUkMBwJXOzXZewF4kxX7F4rCybUl4 YxpySAk3Z2iVXAFWwMosHV6oUw== X-Received: by 2002:a17:902:6f01:b029:dc:3182:ce69 with SMTP id w1-20020a1709026f01b02900dc3182ce69mr16778961plk.10.1608628378460; Tue, 22 Dec 2020 01:12:58 -0800 (PST) Received: from localhost ([122.172.20.109]) by smtp.gmail.com with ESMTPSA id q12sm19544480pgj.24.2020.12.22.01.12.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Dec 2020 01:12:57 -0800 (PST) Date: Tue, 22 Dec 2020 14:42:55 +0530 From: Viresh Kumar To: Dmitry Osipenko Cc: Thierry Reding , Jonathan Hunter , Mark Brown , Liam Girdwood , Ulf Hansson , Mauro Carvalho Chehab , Rob Herring , Peter Geis , Nicolas Chauvet , Krzysztof Kozlowski , "Rafael J. Wysocki" , Kevin Hilman , Peter De Schrijver , Viresh Kumar , Stephen Boyd , Michael Turquette , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linux-tegra@vger.kernel.org, linux-clk@vger.kernel.org Subject: Re: [PATCH v2 19/48] opp: Fix adding OPP entries in a wrong order if rate is unavailable Message-ID: <20201222091255.wentz5hyt726qezg@vireshk-i7> References: <20201217180638.22748-1-digetx@gmail.com> <20201217180638.22748-20-digetx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201217180638.22748-20-digetx@gmail.com> User-Agent: NeoMutt/20180716-391-311a52 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17-12-20, 21:06, Dmitry Osipenko wrote: > Fix adding OPP entries in a wrong (opposite) order if OPP rate is > unavailable. The OPP comparison is erroneously skipped if OPP rate is > missing, thus OPPs are left unsorted. > > Signed-off-by: Dmitry Osipenko > --- > drivers/opp/core.c | 23 ++++++++++++----------- > drivers/opp/opp.h | 2 +- > 2 files changed, 13 insertions(+), 12 deletions(-) > > diff --git a/drivers/opp/core.c b/drivers/opp/core.c > index 34f7e530d941..5c7f130a8de2 100644 > --- a/drivers/opp/core.c > +++ b/drivers/opp/core.c > @@ -1531,9 +1531,10 @@ static bool _opp_supported_by_regulators(struct dev_pm_opp *opp, > return true; > } > > -int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2) > +int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2, > + bool rate_not_available) > { > - if (opp1->rate != opp2->rate) > + if (!rate_not_available && opp1->rate != opp2->rate) rate will be 0 for both the OPPs here if rate_not_available is true and so this change shouldn't be required. > return opp1->rate < opp2->rate ? -1 : 1; > if (opp1->bandwidth && opp2->bandwidth && > opp1->bandwidth[0].peak != opp2->bandwidth[0].peak) > @@ -1545,7 +1546,8 @@ int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2) > > static int _opp_is_duplicate(struct device *dev, struct dev_pm_opp *new_opp, > struct opp_table *opp_table, > - struct list_head **head) > + struct list_head **head, > + bool rate_not_available) > { > struct dev_pm_opp *opp; > int opp_cmp; > @@ -1559,13 +1561,13 @@ static int _opp_is_duplicate(struct device *dev, struct dev_pm_opp *new_opp, > * loop. > */ > list_for_each_entry(opp, &opp_table->opp_list, node) { > - opp_cmp = _opp_compare_key(new_opp, opp); > + opp_cmp = _opp_compare_key(new_opp, opp, rate_not_available); > if (opp_cmp > 0) { > *head = &opp->node; > continue; > } > > - if (opp_cmp < 0) > + if (opp_cmp < 0 || rate_not_available) > return 0; This shouldn't be required as well, isn't it ? > > /* Duplicate OPPs */ > @@ -1601,12 +1603,11 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, > mutex_lock(&opp_table->lock); > head = &opp_table->opp_list; > > - if (likely(!rate_not_available)) { > - ret = _opp_is_duplicate(dev, new_opp, opp_table, &head); > - if (ret) { > - mutex_unlock(&opp_table->lock); > - return ret; > - } > + ret = _opp_is_duplicate(dev, new_opp, opp_table, &head, > + rate_not_available); This is the only thing we need to do here I believe. > + if (ret) { > + mutex_unlock(&opp_table->lock); > + return ret; > } > > list_add(&new_opp->node, head); > diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h > index 4ced7ffa8158..6f5be6c72f13 100644 > --- a/drivers/opp/opp.h > +++ b/drivers/opp/opp.h > @@ -219,7 +219,7 @@ struct opp_table *_find_opp_table(struct device *dev); > struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table); > struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table); > void _opp_free(struct dev_pm_opp *opp); > -int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2); > +int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2, bool rate_not_available); > int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, bool rate_not_available); > int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic); > void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cpu); > -- > 2.29.2 -- viresh