Commit 9b3cc56c authored by Rob Herring (Arm)'s avatar Rob Herring (Arm) Committed by Viresh Kumar

cpufreq: spear: Use of_property_for_each_u32() instead of open coding

Use of_property_count_u32_elems() and of_property_for_each_u32() instead
of of_find_property() and open coding the property parsing.

This is part of a larger effort to remove callers of of_find_property()
and similar functions. of_find_property() leaks the DT struct property
and data pointers which is a problem for dynamically allocated nodes
which may be freed.
Signed-off-by: default avatarRob Herring (Arm) <robh@kernel.org>
[Viresh: Fixed build failure and initialize / increment 'i']
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
parent 872cc94c
...@@ -171,10 +171,9 @@ static struct cpufreq_driver spear_cpufreq_driver = { ...@@ -171,10 +171,9 @@ static struct cpufreq_driver spear_cpufreq_driver = {
static int spear_cpufreq_probe(struct platform_device *pdev) static int spear_cpufreq_probe(struct platform_device *pdev)
{ {
struct device_node *np; struct device_node *np;
const struct property *prop;
struct cpufreq_frequency_table *freq_tbl; struct cpufreq_frequency_table *freq_tbl;
const __be32 *val; u32 val;
int cnt, i, ret; int cnt, ret, i = 0;
np = of_cpu_device_node_get(0); np = of_cpu_device_node_get(0);
if (!np) { if (!np) {
...@@ -186,26 +185,23 @@ static int spear_cpufreq_probe(struct platform_device *pdev) ...@@ -186,26 +185,23 @@ static int spear_cpufreq_probe(struct platform_device *pdev)
&spear_cpufreq.transition_latency)) &spear_cpufreq.transition_latency))
spear_cpufreq.transition_latency = CPUFREQ_ETERNAL; spear_cpufreq.transition_latency = CPUFREQ_ETERNAL;
prop = of_find_property(np, "cpufreq_tbl", NULL); cnt = of_property_count_u32_elems(np, "cpufreq_tbl");
if (!prop || !prop->value) { if (cnt <= 0) {
pr_err("Invalid cpufreq_tbl\n"); pr_err("Invalid cpufreq_tbl\n");
ret = -ENODEV; ret = -ENODEV;
goto out_put_node; goto out_put_node;
} }
cnt = prop->length / sizeof(u32);
val = prop->value;
freq_tbl = kcalloc(cnt + 1, sizeof(*freq_tbl), GFP_KERNEL); freq_tbl = kcalloc(cnt + 1, sizeof(*freq_tbl), GFP_KERNEL);
if (!freq_tbl) { if (!freq_tbl) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_put_node; goto out_put_node;
} }
for (i = 0; i < cnt; i++) of_property_for_each_u32(np, "cpufreq_tbl", val)
freq_tbl[i].frequency = be32_to_cpup(val++); freq_tbl[i++].frequency = val;
freq_tbl[i].frequency = CPUFREQ_TABLE_END; freq_tbl[cnt].frequency = CPUFREQ_TABLE_END;
spear_cpufreq.freq_tbl = freq_tbl; spear_cpufreq.freq_tbl = freq_tbl;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment