Skip to content

Commit 120e117

Browse files
Georgi Djakovvireshk
authored andcommitted
opp: Add sanity checks in _read_opp_key()
When we read the OPP keys, it would be nice to do some sanity checks of the values we get from DT and see if they match with the information that is populated in the OPP table. Let's pass a pointer of the table, so that we can do some validation. Signed-off-by: Georgi Djakov <[email protected]> Reviewed-by: Matthias Kaehlcke <[email protected]> Reviewed-by: Sibi Sankar <[email protected]> [ Viresh: Fix rebase conflicts ] Signed-off-by: Viresh Kumar <[email protected]>
1 parent 6d3f922 commit 120e117

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

drivers/opp/of.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ void dev_pm_opp_of_remove_table(struct device *dev)
577577
}
578578
EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);
579579

580-
static int _read_bw(struct dev_pm_opp *new_opp, struct device_node *np,
581-
bool peak)
580+
static int _read_bw(struct dev_pm_opp *new_opp, struct opp_table *table,
581+
struct device_node *np, bool peak)
582582
{
583583
const char *name = peak ? "opp-peak-kBps" : "opp-avg-kBps";
584584
struct property *prop;
@@ -590,6 +590,12 @@ static int _read_bw(struct dev_pm_opp *new_opp, struct device_node *np,
590590
return -ENODEV;
591591

592592
count = prop->length / sizeof(u32);
593+
if (table->path_count != count) {
594+
pr_err("%s: Mismatch between %s and paths (%d %d)\n",
595+
__func__, name, count, table->path_count);
596+
return -EINVAL;
597+
}
598+
593599
bw = kmalloc_array(count, sizeof(*bw), GFP_KERNEL);
594600
if (!bw)
595601
return -ENOMEM;
@@ -612,8 +618,8 @@ static int _read_bw(struct dev_pm_opp *new_opp, struct device_node *np,
612618
return ret;
613619
}
614620

615-
static int _read_opp_key(struct dev_pm_opp *new_opp, struct device_node *np,
616-
bool *rate_not_available)
621+
static int _read_opp_key(struct dev_pm_opp *new_opp, struct opp_table *table,
622+
struct device_node *np, bool *rate_not_available)
617623
{
618624
bool found = false;
619625
u64 rate;
@@ -636,10 +642,10 @@ static int _read_opp_key(struct dev_pm_opp *new_opp, struct device_node *np,
636642
* opp-peak-kBps = <path1_value path2_value>;
637643
* opp-avg-kBps = <path1_value path2_value>;
638644
*/
639-
ret = _read_bw(new_opp, np, true);
645+
ret = _read_bw(new_opp, table, np, true);
640646
if (!ret) {
641647
found = true;
642-
ret = _read_bw(new_opp, np, false);
648+
ret = _read_bw(new_opp, table, np, false);
643649
}
644650

645651
/* The properties were found but we failed to parse them */
@@ -692,7 +698,7 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table,
692698
if (!new_opp)
693699
return ERR_PTR(-ENOMEM);
694700

695-
ret = _read_opp_key(new_opp, np, &rate_not_available);
701+
ret = _read_opp_key(new_opp, opp_table, np, &rate_not_available);
696702
if (ret < 0 && !opp_table->is_genpd) {
697703
dev_err(dev, "%s: opp key field not found\n", __func__);
698704
goto free_opp;

0 commit comments

Comments
 (0)