提交 6ce4184d 编写于 作者: V Viresh Kumar 提交者: Rafael J. Wysocki

PM / OPP: do error handling at the bottom of dev_pm_opp_add_dynamic()

This makes it less error prone and moves common resource deallocation at a
single place.
Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
上级 07cce74a
...@@ -413,6 +413,7 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq, ...@@ -413,6 +413,7 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq,
struct device_opp *dev_opp = NULL; struct device_opp *dev_opp = NULL;
struct dev_pm_opp *opp, *new_opp; struct dev_pm_opp *opp, *new_opp;
struct list_head *head; struct list_head *head;
int ret;
/* allocate new OPP node */ /* allocate new OPP node */
new_opp = kzalloc(sizeof(*new_opp), GFP_KERNEL); new_opp = kzalloc(sizeof(*new_opp), GFP_KERNEL);
...@@ -435,9 +436,8 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq, ...@@ -435,9 +436,8 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq,
if (IS_ERR(dev_opp)) { if (IS_ERR(dev_opp)) {
dev_opp = add_device_opp(dev); dev_opp = add_device_opp(dev);
if (!dev_opp) { if (!dev_opp) {
mutex_unlock(&dev_opp_list_lock); ret = -ENOMEM;
kfree(new_opp); goto free_opp;
return -ENOMEM;
} }
head = &dev_opp->opp_list; head = &dev_opp->opp_list;
...@@ -458,15 +458,13 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq, ...@@ -458,15 +458,13 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq,
/* Duplicate OPPs ? */ /* Duplicate OPPs ? */
if (new_opp->rate == opp->rate) { if (new_opp->rate == opp->rate) {
int ret = opp->available && new_opp->u_volt == opp->u_volt ? ret = opp->available && new_opp->u_volt == opp->u_volt ?
0 : -EEXIST; 0 : -EEXIST;
dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n", dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n",
__func__, opp->rate, opp->u_volt, opp->available, __func__, opp->rate, opp->u_volt, opp->available,
new_opp->rate, new_opp->u_volt, new_opp->available); new_opp->rate, new_opp->u_volt, new_opp->available);
mutex_unlock(&dev_opp_list_lock); goto free_opp;
kfree(new_opp);
return ret;
} }
list_add: list_add:
...@@ -480,6 +478,11 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq, ...@@ -480,6 +478,11 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq,
*/ */
srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_ADD, new_opp); srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_ADD, new_opp);
return 0; return 0;
free_opp:
mutex_unlock(&dev_opp_list_lock);
kfree(new_opp);
return ret;
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册