Skip to content

Commit 9610404

Browse files
committed
OPP: Add _link_required_opps() to avoid code duplication
Factor out _link_required_opps() to remove duplicate code. No functional change. Signed-off-by: Viresh Kumar <[email protected]> Reviewed-by: Ulf Hansson <[email protected]>
1 parent 8e6db12 commit 9610404

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

drivers/opp/of.c

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -296,46 +296,51 @@ void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp)
296296
of_node_put(opp->np);
297297
}
298298

299+
static int _link_required_opps(struct dev_pm_opp *opp,
300+
struct opp_table *required_table, int index)
301+
{
302+
struct device_node *np;
303+
304+
np = of_parse_required_opp(opp->np, index);
305+
if (unlikely(!np))
306+
return -ENODEV;
307+
308+
opp->required_opps[index] = _find_opp_of_np(required_table, np);
309+
of_node_put(np);
310+
311+
if (!opp->required_opps[index]) {
312+
pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
313+
__func__, opp->np, index);
314+
return -ENODEV;
315+
}
316+
317+
return 0;
318+
}
319+
299320
/* Populate all required OPPs which are part of "required-opps" list */
300321
static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
301322
struct dev_pm_opp *opp)
302323
{
303-
struct dev_pm_opp **required_opps;
304324
struct opp_table *required_table;
305-
struct device_node *np;
306325
int i, ret, count = opp_table->required_opp_count;
307326

308327
if (!count)
309328
return 0;
310329

311-
required_opps = kcalloc(count, sizeof(*required_opps), GFP_KERNEL);
312-
if (!required_opps)
330+
opp->required_opps = kcalloc(count, sizeof(*opp->required_opps), GFP_KERNEL);
331+
if (!opp->required_opps)
313332
return -ENOMEM;
314333

315-
opp->required_opps = required_opps;
316-
317334
for (i = 0; i < count; i++) {
318335
required_table = opp_table->required_opp_tables[i];
319336

320337
/* Required table not added yet, we will link later */
321338
if (IS_ERR_OR_NULL(required_table))
322339
continue;
323340

324-
np = of_parse_required_opp(opp->np, i);
325-
if (unlikely(!np)) {
326-
ret = -ENODEV;
327-
goto free_required_opps;
328-
}
329-
330-
required_opps[i] = _find_opp_of_np(required_table, np);
331-
of_node_put(np);
332-
333-
if (!required_opps[i]) {
334-
pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
335-
__func__, opp->np, i);
336-
ret = -ENODEV;
341+
ret = _link_required_opps(opp, required_table, i);
342+
if (ret)
337343
goto free_required_opps;
338-
}
339344
}
340345

341346
return 0;
@@ -350,22 +355,13 @@ static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
350355
static int lazy_link_required_opps(struct opp_table *opp_table,
351356
struct opp_table *new_table, int index)
352357
{
353-
struct device_node *required_np;
354358
struct dev_pm_opp *opp;
359+
int ret;
355360

356361
list_for_each_entry(opp, &opp_table->opp_list, node) {
357-
required_np = of_parse_required_opp(opp->np, index);
358-
if (unlikely(!required_np))
359-
return -ENODEV;
360-
361-
opp->required_opps[index] = _find_opp_of_np(new_table, required_np);
362-
of_node_put(required_np);
363-
364-
if (!opp->required_opps[index]) {
365-
pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
366-
__func__, opp->np, index);
367-
return -ENODEV;
368-
}
362+
ret = _link_required_opps(opp, new_table, index);
363+
if (ret)
364+
return ret;
369365
}
370366

371367
return 0;

0 commit comments

Comments
 (0)