Skip to content

Commit 9b3cc56

Browse files
robherringvireshk
authored andcommitted
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: Rob Herring (Arm) <[email protected]> [Viresh: Fixed build failure and initialize / increment 'i'] Signed-off-by: Viresh Kumar <[email protected]>
1 parent 872cc94 commit 9b3cc56

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

drivers/cpufreq/spear-cpufreq.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,9 @@ static struct cpufreq_driver spear_cpufreq_driver = {
171171
static int spear_cpufreq_probe(struct platform_device *pdev)
172172
{
173173
struct device_node *np;
174-
const struct property *prop;
175174
struct cpufreq_frequency_table *freq_tbl;
176-
const __be32 *val;
177-
int cnt, i, ret;
175+
u32 val;
176+
int cnt, ret, i = 0;
178177

179178
np = of_cpu_device_node_get(0);
180179
if (!np) {
@@ -186,26 +185,23 @@ static int spear_cpufreq_probe(struct platform_device *pdev)
186185
&spear_cpufreq.transition_latency))
187186
spear_cpufreq.transition_latency = CPUFREQ_ETERNAL;
188187

189-
prop = of_find_property(np, "cpufreq_tbl", NULL);
190-
if (!prop || !prop->value) {
188+
cnt = of_property_count_u32_elems(np, "cpufreq_tbl");
189+
if (cnt <= 0) {
191190
pr_err("Invalid cpufreq_tbl\n");
192191
ret = -ENODEV;
193192
goto out_put_node;
194193
}
195194

196-
cnt = prop->length / sizeof(u32);
197-
val = prop->value;
198-
199195
freq_tbl = kcalloc(cnt + 1, sizeof(*freq_tbl), GFP_KERNEL);
200196
if (!freq_tbl) {
201197
ret = -ENOMEM;
202198
goto out_put_node;
203199
}
204200

205-
for (i = 0; i < cnt; i++)
206-
freq_tbl[i].frequency = be32_to_cpup(val++);
201+
of_property_for_each_u32(np, "cpufreq_tbl", val)
202+
freq_tbl[i++].frequency = val;
207203

208-
freq_tbl[i].frequency = CPUFREQ_TABLE_END;
204+
freq_tbl[cnt].frequency = CPUFREQ_TABLE_END;
209205

210206
spear_cpufreq.freq_tbl = freq_tbl;
211207

0 commit comments

Comments
 (0)