Skip to content

Commit 1a6a8b0

Browse files
konradybciovireshk
authored andcommitted
cpufreq: qcom-hw: Fix reading "reg" with address/size-cells != 2
Commit 054a3ef ("cpufreq: qcom-hw: Allocate qcom_cpufreq_data during probe") assumed that every reg variable is 4*u32 wide (as most new qcom SoCs set #address- and #size-cells to <2>. That is not the case for all of them though. Check the cells values dynamically to ensure the proper region of the DTB is being read. Fixes: 054a3ef ("cpufreq: qcom-hw: Allocate qcom_cpufreq_data during probe") Signed-off-by: Konrad Dybcio <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent f5f94b9 commit 1a6a8b0

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

drivers/cpufreq/qcom-cpufreq-hw.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,10 @@ static int qcom_cpufreq_hw_driver_probe(struct platform_device *pdev)
649649
{
650650
struct clk_hw_onecell_data *clk_data;
651651
struct device *dev = &pdev->dev;
652+
struct device_node *soc_node;
652653
struct device *cpu_dev;
653654
struct clk *clk;
654-
int ret, i, num_domains;
655+
int ret, i, num_domains, reg_sz;
655656

656657
clk = clk_get(dev, "xo");
657658
if (IS_ERR(clk))
@@ -679,7 +680,21 @@ static int qcom_cpufreq_hw_driver_probe(struct platform_device *pdev)
679680
return ret;
680681

681682
/* Allocate qcom_cpufreq_data based on the available frequency domains in DT */
682-
num_domains = of_property_count_elems_of_size(dev->of_node, "reg", sizeof(u32) * 4);
683+
soc_node = of_get_parent(dev->of_node);
684+
if (!soc_node)
685+
return -EINVAL;
686+
687+
ret = of_property_read_u32(soc_node, "#address-cells", &reg_sz);
688+
if (ret)
689+
goto of_exit;
690+
691+
ret = of_property_read_u32(soc_node, "#size-cells", &i);
692+
if (ret)
693+
goto of_exit;
694+
695+
reg_sz += i;
696+
697+
num_domains = of_property_count_elems_of_size(dev->of_node, "reg", sizeof(u32) * reg_sz);
683698
if (num_domains <= 0)
684699
return num_domains;
685700

@@ -743,6 +758,9 @@ static int qcom_cpufreq_hw_driver_probe(struct platform_device *pdev)
743758
else
744759
dev_dbg(dev, "QCOM CPUFreq HW driver initialized\n");
745760

761+
of_exit:
762+
of_node_put(soc_node);
763+
746764
return ret;
747765
}
748766

0 commit comments

Comments
 (0)