Skip to content

Commit 7ddd8de

Browse files
Mani-Sadhasivamvireshk
authored andcommitted
OPP: Fix potential null ptr dereference in dev_pm_opp_get_required_pstate()
"opp" pointer is dereferenced before the IS_ERR_OR_NULL() check. Fix it by removing the dereference to cache opp_table and dereference it directly where opp_table is used. This fixes the following smatch warning: drivers/opp/core.c:232 dev_pm_opp_get_required_pstate() warn: variable dereferenced before IS_ERR check 'opp' (see line 230) Fixes: 84cb7ff ("OPP: pstate is only valid for genpd OPP tables") Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent 746de82 commit 7ddd8de

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

drivers/opp/core.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,18 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_level);
226226
unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
227227
unsigned int index)
228228
{
229-
struct opp_table *opp_table = opp->opp_table;
230-
231229
if (IS_ERR_OR_NULL(opp) || !opp->available ||
232-
index >= opp_table->required_opp_count) {
230+
index >= opp->opp_table->required_opp_count) {
233231
pr_err("%s: Invalid parameters\n", __func__);
234232
return 0;
235233
}
236234

237235
/* required-opps not fully initialized yet */
238-
if (lazy_linking_pending(opp_table))
236+
if (lazy_linking_pending(opp->opp_table))
239237
return 0;
240238

241239
/* The required OPP table must belong to a genpd */
242-
if (unlikely(!opp_table->required_opp_tables[index]->is_genpd)) {
240+
if (unlikely(!opp->opp_table->required_opp_tables[index]->is_genpd)) {
243241
pr_err("%s: Performance state is only valid for genpds.\n", __func__);
244242
return 0;
245243
}

0 commit comments

Comments
 (0)