OPP: Compare bandwidths for all paths in _opp_compare_key()
authorViresh Kumar <viresh.kumar@linaro.org>
Tue, 5 Jul 2022 06:20:47 +0000 (11:50 +0530)
committerViresh Kumar <viresh.kumar@linaro.org>
Tue, 12 Jul 2022 15:05:20 +0000 (20:35 +0530)
Replicate the same behavior as "rates" here and compare all values
instead of relying on the first entry alone.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
drivers/opp/core.c

index e3322d54942a2b2acc8db3e9fa9c77e17673fe64..d695f68fba8c058787af7df5707d6b906c7cf985 100644 (file)
@@ -1697,6 +1697,20 @@ static int _opp_compare_rate(struct opp_table *opp_table,
        return 0;
 }
 
+static int _opp_compare_bw(struct opp_table *opp_table, struct dev_pm_opp *opp1,
+                          struct dev_pm_opp *opp2)
+{
+       int i;
+
+       for (i = 0; i < opp_table->path_count; i++) {
+               if (opp1->bandwidth[i].peak != opp2->bandwidth[i].peak)
+                       return opp1->bandwidth[i].peak < opp2->bandwidth[i].peak ? -1 : 1;
+       }
+
+       /* Same bw for both OPPs */
+       return 0;
+}
+
 /*
  * Returns
  * 0: opp1 == opp2
@@ -1712,9 +1726,9 @@ int _opp_compare_key(struct opp_table *opp_table, struct dev_pm_opp *opp1,
        if (ret)
                return ret;
 
-       if (opp1->bandwidth && opp2->bandwidth &&
-           opp1->bandwidth[0].peak != opp2->bandwidth[0].peak)
-               return opp1->bandwidth[0].peak < opp2->bandwidth[0].peak ? -1 : 1;
+       ret = _opp_compare_bw(opp_table, opp1, opp2);
+       if (ret)
+               return ret;
 
        if (opp1->level != opp2->level)
                return opp1->level < opp2->level ? -1 : 1;