Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3486243imm; Sun, 30 Sep 2018 22:19:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV63hZ8Lk/FnwiAywb3yMs6pDB1/UlXKC5+KwZE7HtfUgpARVK9A0TXKwtuz+QMaROGRT5nZw X-Received: by 2002:a17:902:3a5:: with SMTP id d34-v6mr9985016pld.98.1538371189472; Sun, 30 Sep 2018 22:19:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538371189; cv=none; d=google.com; s=arc-20160816; b=EURFsb471Yr6tMU/THUoiSiwfPVq4g06kyDs6dK6g8ove/Uov/BYOsf+u/ySjsfIez AhpbWOeEDKjC3k9u9i7XpTiBzRpWql70fD/6u6jiuPfzQ40UzgabL3FWOTxMQaYas5ue qL+6Yacsmgt0E86cbG5vyQWYw35qkYEo6gzICNFWT6dI/qNswGPVU3i23g4JwLqv3OJL 1TOXXoGas0E5E4GGz2u874XqBm90wwecyidx2KoM153kKXfzqnpTRbAT5M4VXWAWBq3T 7ykaiElNeG76S69KXlfOnTrefTxzat5Ne1arTLVJ/qSrIRW9yPWHliO9wNCwcgf2dkJk F3Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ZNepvVin512d3+WA7lhYg2Xcy6C6uCToYmc3IggMMIU=; b=Z401bo8CVc6PSB1B8aOosuYg7SKyQZD6nZP8eMGX1bnSrnIP0ONu/mOZ7f3uAf/aJu Z3+ryz7A98jyHzq1pGqQKaqwXVHT1U7aZR3oqmsTpq9K7d75XgRKpNb1ui9twqmIPpid QGmsJ9rJTIisTbxpyAONmlZsTfexJnTqISynixsE1fncgiBHTLSdOOOdWyrn99ODHGAF SU3CUXF0CLbGF3gtydMZlICo76T2mlCcJYwCf53Xm37y7qRsCil8duGczbD+wfguLJn8 u9Gl2jLAAswZ6u6iWcr6fboT/BWLDXIAM5zuX4Ba1gzvM0Vv/OsAEs6j830+lmTAJNiP 4Zzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GXyu9UKv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id i7-v6si10363378pgs.174.2018.09.30.22.19.34; Sun, 30 Sep 2018 22:19:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GXyu9UKv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728632AbeJALz1 (ORCPT + 99 others); Mon, 1 Oct 2018 07:55:27 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34121 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728555AbeJALz1 (ORCPT ); Mon, 1 Oct 2018 07:55:27 -0400 Received: by mail-pg1-f195.google.com with SMTP id g12-v6so2908522pgs.1 for ; Sun, 30 Sep 2018 22:19:30 -0700 (PDT) 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=ZNepvVin512d3+WA7lhYg2Xcy6C6uCToYmc3IggMMIU=; b=GXyu9UKv/9rDp+kVU1a49tuSsvQwMX2Huu1DwZ/tcxSfwrB2+6/ON0Xo7uzQjf/4ke 4jbWTaoy0OojzJ4hQjBEoLBnDQQn7hI0LSTT7Lqu+uvWO60Ze10VRz9LBCkUSCeTydsY A2M+MpKwBRNmKVvsojbF4m8ERswGtVONh2FX0= 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=ZNepvVin512d3+WA7lhYg2Xcy6C6uCToYmc3IggMMIU=; b=Hv2miJfS5jY3olmPc+BvnRdJcDWhK/0N6YvhmV8fcdtATpYcn+GyYpYLea2b1HXeWT n74D9EPGHBTwEQ4Ob2YtER8OAbR8xl2c9CAL4HcMhpBisINvUzHAlx9Ks3EIYMNjoUvc IlZBEmXgSx8IpBr7gy77fLD+10bR+rVWUlYRvUUD45ym71f3zfcoZZSNDTT91xlAfSY+ 12cwWALen5B+KLaVPl2Ikjg99O8+7mmVocwn7zxOmb8yJ2TLuGZQWTOqRAM/hIa+JuC4 tUDf+dvRS2HpOaERiOKzUxyj6TwI+tYDpEW8H+yhGoXiYn+SQ2mg8rSmJZf13rpci7Ff Az6Q== X-Gm-Message-State: ABuFfoitNJc4sjoXaXCxakd5BmQgQsmCCvQfoChXGbaUS+lY/N/tUTXb YXumNjOcP5etj5MjknFmcV2pIQ== X-Received: by 2002:a17:902:6501:: with SMTP id b1-v6mr10021330plk.31.1538371169643; Sun, 30 Sep 2018 22:19:29 -0700 (PDT) Received: from localhost ([122.172.136.196]) by smtp.gmail.com with ESMTPSA id t14-v6sm13465158pgu.0.2018.09.30.22.19.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 22:19:28 -0700 (PDT) Date: Mon, 1 Oct 2018 10:49:26 +0530 From: Viresh Kumar To: Dave Gerlach Cc: "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Tony Lindgren , Tero Kristo , Nishanth Menon , Stephen Boyd , Keerthy J Subject: Re: [PATCH] PM / OPP: Refactor counting of added OPPs for v2 to avoid unsupported OPPs Message-ID: <20181001051925.u3lpcg537xomsckp@vireshk-i7> References: <20180822031035.6937-1-d-gerlach@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180822031035.6937-1-d-gerlach@ti.com> User-Agent: NeoMutt/20180323-120-3dd1ac Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21-08-18, 22:10, Dave Gerlach wrote: Please ping people back if you haven't received a response for too long. Sorry that I missed getting to this at an earlier point of time. > Currently the _of_add_opp_table_v2 call loops through the OPP nodes in > the operating-points-v2 table in the device tree and calls > _opp_add_static_v2 for each to add them to the table. It counts each > iteration through this loop as an added OPP, however on platforms making > use of the opp-supported-hw property, _opp_add_static_v2 does not add > OPPs that are not seen as supported on the platform but still returns > success, as this is valid. Because of this the count variable will > contain the number of OPP nodes in the table in device tree but not > necessarily the ones that are supported and actually added. > > As this count value is what is checked to determine if there are any > valid OPPs, if a platform has an operating-points-v2 table with all OPP > nodes containing opp-supported-hw values that are not currently > supported then _of_add_opp_table_v2 will fail to abort as it should due > to an empty table. > > Additionally, since commit 3ba98324e81a ("PM / OPP: Get > performance state using genpd helper"), the same count variable is > compared against the number of OPPs containing performance states and > requires that either all or none have pstates set, however in the case > of any opp table that has any entries that do not get added by > _opp_add_static_v2 due to incompatible opp-supported-hw fields, these > numbers will not match and _of_add_opp_table_v2 will incorrectly fail. > > In order to ensure the count variable reflects the number of OPPs > actually in the table, increment it during the existing loop which walks > the opp table to check if pstate is set and then use that for the > aforementioned checks. > > Fixes: 3ba98324e81a ("PM / OPP: Get performance state using genpd helper") > Signed-off-by: Dave Gerlach > --- > drivers/opp/of.c | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > > diff --git a/drivers/opp/of.c b/drivers/opp/of.c > index 7af0ddec936b..f288f83a2e62 100644 > --- a/drivers/opp/of.c > +++ b/drivers/opp/of.c > @@ -399,8 +399,6 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) > > /* We have opp-table node now, iterate over it and add OPPs */ > for_each_available_child_of_node(opp_np, np) { > - count++; > - > ret = _opp_add_static_v2(opp_table, dev, np); > if (ret) { > dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, > @@ -411,15 +409,22 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) > } > } > > + /* > + * Iterate over the list of OPPs that were actually added, as > + * OPPs not supported by the hardware will be ignored by > + * _opp_add_static_v2 above. > + */ > + list_for_each_entry(opp, &opp_table->opp_list, node) { > + count++; > + pstate_count += !!opp->pstate; > + } So the problem is genuine and is still true with the latest code in linux-next, but this patch wouldn't fix all cases. What if some OPPs were dynamically added using dev_pm_opp_add() and everything failed in this routine? We will still have the problem you are trying to fix here. What needs to be done is to identify the case where the OPP wasn't supported. Maybe return the new OPPs pointer from _opp_add_static_v2(), return -ve ERR_PTR values on error and NULL for the case where OPP isn't added but that's not an error. Apart from your example another case is of duplicate OPPs where we return 0 without adding the OPP. Please post patch against linux-next as some updates are already pushed for OPP core there. -- viresh