PM / OPP: Free resources and properly return error on failure
authorViresh Kumar <viresh.kumar@linaro.org>
Wed, 12 Aug 2015 11:00:18 +0000 (16:30 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 28 Aug 2015 02:33:06 +0000 (04:33 +0200)
_of_init_opp_table_v2() isn't freeing up resources on some errors and
the error values returned are also not correct always.

This fixes following problems:
- Return -ENOENT, if no entries are found in the table.
- Use IS_ERR() to properly check return value of _find_device_opp().
- Return error value with PTR_ERR() in above case.
- Free table if _find_device_opp() fails.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/opp.c

index 204c6c945168674192c53d4dd5ac7934ea0599d5..4d6c4576f7ae090c39bcefbf5975ad8e75453fb1 100644 (file)
@@ -1323,28 +1323,30 @@ static int _of_init_opp_table_v2(struct device *dev,
                if (ret) {
                        dev_err(dev, "%s: Failed to add OPP, %d\n", __func__,
                                ret);
-                       break;
+                       goto free_table;
                }
        }
 
        /* There should be one of more OPP defined */
-       if (WARN_ON(!count))
+       if (WARN_ON(!count)) {
+               ret = -ENOENT;
                goto put_opp_np;
+       }
 
-       if (!ret) {
-               if (!dev_opp) {
-                       dev_opp = _find_device_opp(dev);
-                       if (WARN_ON(!dev_opp))
-                               goto put_opp_np;
-               }
-
-               dev_opp->np = opp_np;
-               dev_opp->shared_opp = of_property_read_bool(opp_np,
-                                                           "opp-shared");
-       } else {
-               of_free_opp_table(dev);
+       dev_opp = _find_device_opp(dev);
+       if (WARN_ON(IS_ERR(dev_opp))) {
+               ret = PTR_ERR(dev_opp);
+               goto free_table;
        }
 
+       dev_opp->np = opp_np;
+       dev_opp->shared_opp = of_property_read_bool(opp_np, "opp-shared");
+
+       of_node_put(opp_np);
+       return 0;
+
+free_table:
+       of_free_opp_table(dev);
 put_opp_np:
        of_node_put(opp_np);