From: Konrad Dybcio <konrad.dybcio@linaro.org>
To: linux-arm-msm@vger.kernel.org, andersson@kernel.org,
agross@kernel.org, krzysztof.kozlowski@linaro.org
Cc: marijn.suijten@somainline.org,
Konrad Dybcio <konrad.dybcio@linaro.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Manivannan Sadhasivam <mani@kernel.org>,
linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] cpufreq: qcom-hw: Ensure only freq-domain regs are counted in num_domains
Date: Wed, 11 Jan 2023 21:51:25 +0100 [thread overview]
Message-ID: <20230111205125.1860858-2-konrad.dybcio@linaro.org> (raw)
In-Reply-To: <20230111205125.1860858-1-konrad.dybcio@linaro.org>
In preparation for CPRh-aware OSM programming, change the probe
function so that we determine the number of frequency domains by
counting the number of reg-names entries that begin with
"freq-domain", as the aforementioned changes require introduction
of non-freq-domain register spaces.
Fixes: 1a6a8b0080b0 ("cpufreq: qcom-hw: Fix reading "reg" with address/size-cells != 2")
Fixes: 054a3ef683a1 ("cpufreq: qcom-hw: Allocate qcom_cpufreq_data during probe")
Signed-off-by: Konrad Dybcio <konrad.dybcio@linaro.org>
---
drivers/cpufreq/qcom-cpufreq-hw.c | 34 ++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c
index 9505a812d6a1..89d5ed267399 100644
--- a/drivers/cpufreq/qcom-cpufreq-hw.c
+++ b/drivers/cpufreq/qcom-cpufreq-hw.c
@@ -651,8 +651,9 @@ static int qcom_cpufreq_hw_driver_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct device_node *soc_node;
struct device *cpu_dev;
+ const char *reg_name;
struct clk *clk;
- int ret, i, num_domains, reg_sz;
+ int ret, i, num_reg_names, num_domains = 0;
clk = clk_get(dev, "xo");
if (IS_ERR(clk))
@@ -684,19 +685,32 @@ static int qcom_cpufreq_hw_driver_probe(struct platform_device *pdev)
if (!soc_node)
return -EINVAL;
- ret = of_property_read_u32(soc_node, "#address-cells", ®_sz);
- if (ret)
+ num_reg_names = of_property_count_strings(dev->of_node, "reg-names");
+ if (num_reg_names <= 0) {
+ ret = num_reg_names ? num_reg_names : -ENODATA;
goto of_exit;
+ }
- ret = of_property_read_u32(soc_node, "#size-cells", &i);
- if (ret)
- goto of_exit;
+ for (i = 0; i < num_reg_names; i++) {
+ ret = of_property_read_string_index(dev->of_node, "reg-names", i, ®_name);
+ if (ret < 0)
+ goto of_exit;
- reg_sz += i;
+ /*
+ * Check if the i-th reg is a freq-domain base, no need to add 1
+ * more byte for idx, as sizeof counts \0 whereas strlen does not.
+ */
+ if (strlen(reg_name) == sizeof("freq-domain")) {
+ /* Check if this reg-name begins with "freq-domain" */
+ if (!strncmp(reg_name, "freq-domain", sizeof("freq-domain") - 1))
+ num_domains++;
+ }
+ }
- num_domains = of_property_count_elems_of_size(dev->of_node, "reg", sizeof(u32) * reg_sz);
- if (num_domains <= 0)
- return num_domains;
+ if (num_domains <= 0) {
+ ret = -EINVAL;
+ goto of_exit;
+ }
qcom_cpufreq.data = devm_kzalloc(dev, sizeof(struct qcom_cpufreq_data) * num_domains,
GFP_KERNEL);
--
2.39.0
next prev parent reply other threads:[~2023-01-11 20:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 20:51 [PATCH 1/2] dt-bindings: cpufreq: Make reg-names a required property Konrad Dybcio
2023-01-11 20:51 ` Konrad Dybcio [this message]
2023-01-12 15:37 ` [PATCH 2/2] cpufreq: qcom-hw: Ensure only freq-domain regs are counted in num_domains Bjorn Andersson
2023-01-12 15:41 ` Konrad Dybcio
2023-01-13 19:41 ` Rob Herring
2023-01-14 20:42 ` Konrad Dybcio
2023-01-15 4:36 ` Manivannan Sadhasivam
2023-01-15 4:37 ` [PATCH 1/2] dt-bindings: cpufreq: Make reg-names a required property Manivannan Sadhasivam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230111205125.1860858-2-konrad.dybcio@linaro.org \
--to=konrad.dybcio@linaro.org \
--cc=agross@kernel.org \
--cc=andersson@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mani@kernel.org \
--cc=marijn.suijten@somainline.org \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).