Factor out _link_required_opps() to remove duplicate code. No functional
change.
Signed-off-by: Viresh Kumar <[email protected]>
---
drivers/opp/of.c | 62 ++++++++++++++++++++++--------------------------
1 file changed, 29 insertions(+), 33 deletions(-)
diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index 85e2af3d6a49..81fa27599d58 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -296,24 +296,41 @@ void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp)
of_node_put(opp->np);
}
+static int _link_required_opps(struct dev_pm_opp *opp,
+ struct opp_table *required_table, int index)
+{
+ struct device_node *np;
+
+ np = of_parse_required_opp(opp->np, index);
+ if (unlikely(!np))
+ return -ENODEV;
+
+ opp->required_opps[index] = _find_opp_of_np(required_table, np);
+ of_node_put(np);
+
+ if (!opp->required_opps[index]) {
+ pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
+ __func__, opp->np, index);
+ return -ENODEV;
+ }
+
+ return 0;
+}
+
/* Populate all required OPPs which are part of "required-opps" list */
static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
struct dev_pm_opp *opp)
{
- struct dev_pm_opp **required_opps;
struct opp_table *required_table;
- struct device_node *np;
int i, ret, count = opp_table->required_opp_count;
if (!count)
return 0;
- required_opps = kcalloc(count, sizeof(*required_opps), GFP_KERNEL);
- if (!required_opps)
+ opp->required_opps = kcalloc(count, sizeof(*opp->required_opps), GFP_KERNEL);
+ if (!opp->required_opps)
return -ENOMEM;
- opp->required_opps = required_opps;
-
for (i = 0; i < count; i++) {
required_table = opp_table->required_opp_tables[i];
@@ -321,21 +338,9 @@ static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
if (IS_ERR_OR_NULL(required_table))
continue;
- np = of_parse_required_opp(opp->np, i);
- if (unlikely(!np)) {
- ret = -ENODEV;
- goto free_required_opps;
- }
-
- required_opps[i] = _find_opp_of_np(required_table, np);
- of_node_put(np);
-
- if (!required_opps[i]) {
- pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
- __func__, opp->np, i);
- ret = -ENODEV;
+ ret = _link_required_opps(opp, required_table, i);
+ if (ret)
goto free_required_opps;
- }
}
return 0;
@@ -350,22 +355,13 @@ static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
static int lazy_link_required_opps(struct opp_table *opp_table,
struct opp_table *new_table, int index)
{
- struct device_node *required_np;
struct dev_pm_opp *opp;
+ int ret;
list_for_each_entry(opp, &opp_table->opp_list, node) {
- required_np = of_parse_required_opp(opp->np, index);
- if (unlikely(!required_np))
- return -ENODEV;
-
- opp->required_opps[index] = _find_opp_of_np(new_table, required_np);
- of_node_put(required_np);
-
- if (!opp->required_opps[index]) {
- pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
- __func__, opp->np, index);
- return -ENODEV;
- }
+ ret = _link_required_opps(opp, new_table, index);
+ if (ret)
+ return ret;
}
return 0;
--
2.31.1.272.g89b43f80a514
On Fri, 13 Oct 2023 at 10:48, Viresh Kumar <[email protected]> wrote:
>
> 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]>
Kind regards
Uffe
> ---
> drivers/opp/of.c | 62 ++++++++++++++++++++++--------------------------
> 1 file changed, 29 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/opp/of.c b/drivers/opp/of.c
> index 85e2af3d6a49..81fa27599d58 100644
> --- a/drivers/opp/of.c
> +++ b/drivers/opp/of.c
> @@ -296,24 +296,41 @@ void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp)
> of_node_put(opp->np);
> }
>
> +static int _link_required_opps(struct dev_pm_opp *opp,
> + struct opp_table *required_table, int index)
> +{
> + struct device_node *np;
> +
> + np = of_parse_required_opp(opp->np, index);
> + if (unlikely(!np))
> + return -ENODEV;
> +
> + opp->required_opps[index] = _find_opp_of_np(required_table, np);
> + of_node_put(np);
> +
> + if (!opp->required_opps[index]) {
> + pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
> + __func__, opp->np, index);
> + return -ENODEV;
> + }
> +
> + return 0;
> +}
> +
> /* Populate all required OPPs which are part of "required-opps" list */
> static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
> struct dev_pm_opp *opp)
> {
> - struct dev_pm_opp **required_opps;
> struct opp_table *required_table;
> - struct device_node *np;
> int i, ret, count = opp_table->required_opp_count;
>
> if (!count)
> return 0;
>
> - required_opps = kcalloc(count, sizeof(*required_opps), GFP_KERNEL);
> - if (!required_opps)
> + opp->required_opps = kcalloc(count, sizeof(*opp->required_opps), GFP_KERNEL);
> + if (!opp->required_opps)
> return -ENOMEM;
>
> - opp->required_opps = required_opps;
> -
> for (i = 0; i < count; i++) {
> required_table = opp_table->required_opp_tables[i];
>
> @@ -321,21 +338,9 @@ static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
> if (IS_ERR_OR_NULL(required_table))
> continue;
>
> - np = of_parse_required_opp(opp->np, i);
> - if (unlikely(!np)) {
> - ret = -ENODEV;
> - goto free_required_opps;
> - }
> -
> - required_opps[i] = _find_opp_of_np(required_table, np);
> - of_node_put(np);
> -
> - if (!required_opps[i]) {
> - pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
> - __func__, opp->np, i);
> - ret = -ENODEV;
> + ret = _link_required_opps(opp, required_table, i);
> + if (ret)
> goto free_required_opps;
> - }
> }
>
> return 0;
> @@ -350,22 +355,13 @@ static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
> static int lazy_link_required_opps(struct opp_table *opp_table,
> struct opp_table *new_table, int index)
> {
> - struct device_node *required_np;
> struct dev_pm_opp *opp;
> + int ret;
>
> list_for_each_entry(opp, &opp_table->opp_list, node) {
> - required_np = of_parse_required_opp(opp->np, index);
> - if (unlikely(!required_np))
> - return -ENODEV;
> -
> - opp->required_opps[index] = _find_opp_of_np(new_table, required_np);
> - of_node_put(required_np);
> -
> - if (!opp->required_opps[index]) {
> - pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
> - __func__, opp->np, index);
> - return -ENODEV;
> - }
> + ret = _link_required_opps(opp, new_table, index);
> + if (ret)
> + return ret;
> }
>
> return 0;
> --
> 2.31.1.272.g89b43f80a514
>