Skip to content

Commit b44b9bc

Browse files
superna9999vireshk
authored andcommitted
OPP: fix dev_pm_opp_find_bw_*() when bandwidth table not initialized
If a driver calls dev_pm_opp_find_bw_ceil/floor() the retrieve bandwidth from the OPP table but the bandwidth table was not created because the interconnect properties were missing in the OPP consumer node, the kernel will crash with: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000004 ... pc : _read_bw+0x8/0x10 lr : _opp_table_find_key+0x9c/0x174 ... Call trace: _read_bw+0x8/0x10 (P) _opp_table_find_key+0x9c/0x174 (L) _find_key+0x98/0x168 dev_pm_opp_find_bw_ceil+0x50/0x88 ... In order to fix the crash, create an assert function to check if the bandwidth table was created before trying to get a bandwidth with _read_bw(). Fixes: add1dc0 ("OPP: Use generic key finding helpers for bandwidth key") Signed-off-by: Neil Armstrong <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent d659bc6 commit b44b9bc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/opp/core.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ static bool assert_clk_index(struct opp_table *opp_table,
116116
return opp_table->clk_count > index;
117117
}
118118

119+
/*
120+
* Returns true if bandwidth table is large enough to contain the bandwidth index.
121+
*/
122+
static bool assert_bandwidth_index(struct opp_table *opp_table,
123+
unsigned int index)
124+
{
125+
return opp_table->path_count > index;
126+
}
127+
119128
/**
120129
* dev_pm_opp_get_bw() - Gets the bandwidth corresponding to an opp
121130
* @opp: opp for which bandwidth has to be returned for
@@ -915,7 +924,8 @@ struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, unsigned int *bw,
915924
unsigned long temp = *bw;
916925
struct dev_pm_opp *opp;
917926

918-
opp = _find_key_ceil(dev, &temp, index, true, _read_bw, NULL);
927+
opp = _find_key_ceil(dev, &temp, index, true, _read_bw,
928+
assert_bandwidth_index);
919929
*bw = temp;
920930
return opp;
921931
}
@@ -946,7 +956,8 @@ struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
946956
unsigned long temp = *bw;
947957
struct dev_pm_opp *opp;
948958

949-
opp = _find_key_floor(dev, &temp, index, true, _read_bw, NULL);
959+
opp = _find_key_floor(dev, &temp, index, true, _read_bw,
960+
assert_bandwidth_index);
950961
*bw = temp;
951962
return opp;
952963
}

0 commit comments

Comments
 (0)