]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
OPP: Fix potential null ptr dereference in dev_pm_opp_get_required_pstate()
authorManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Fri, 21 Jul 2023 12:46:33 +0000 (18:16 +0530)
committerViresh Kumar <viresh.kumar@linaro.org>
Mon, 24 Jul 2023 08:01:17 +0000 (13:31 +0530)
"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: 84cb7ff35fcf ("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>
drivers/opp/core.c

index 0ad8664d2423df1d713612cff93685de6566d32e..991c2e894b1a8fb9fa97eb87d3ead11eaeffe7bf 100644 (file)
@@ -226,20 +226,18 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_level);
 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
                                            unsigned int index)
 {
-       struct opp_table *opp_table = opp->opp_table;
-
        if (IS_ERR_OR_NULL(opp) || !opp->available ||
-           index >= opp_table->required_opp_count) {
+           index >= opp->opp_table->required_opp_count) {
                pr_err("%s: Invalid parameters\n", __func__);
                return 0;
        }
 
        /* required-opps not fully initialized yet */
-       if (lazy_linking_pending(opp_table))
+       if (lazy_linking_pending(opp->opp_table))
                return 0;
 
        /* The required OPP table must belong to a genpd */
-       if (unlikely(!opp_table->required_opp_tables[index]->is_genpd)) {
+       if (unlikely(!opp->opp_table->required_opp_tables[index]->is_genpd)) {
                pr_err("%s: Performance state is only valid for genpds.\n", __func__);
                return 0;
        }