summaryrefslogtreecommitdiff
path: root/drivers/devfreq
diff options
context:
space:
mode:
authorYangtao Li <tiny.windzz@gmail.com>2019-01-19 11:04:53 -0500
committerMyungJoo Ham <myungjoo.ham@samsung.com>2019-04-16 09:29:18 +0900
commit25846fa1cedada274b65ffd2413378290a60be47 (patch)
treeb51c50d3889bb3599dca01d2bd318a82767f6840 /drivers/devfreq
parenta9487917ba6728dd618ae6d418a7f2197f1b4592 (diff)
downloadlwn-25846fa1cedada274b65ffd2413378290a60be47.tar.gz
lwn-25846fa1cedada274b65ffd2413378290a60be47.zip
PM / devfreq: fix missing check of return value in devfreq_add_device()
devm_kzalloc() could fail, so insert a check of its return value. And if it fails, returns -ENOMEM. Signed-off-by: Yangtao Li <tiny.windzz@gmail.com> Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Diffstat (limited to 'drivers/devfreq')
-rw-r--r--drivers/devfreq/devfreq.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index fa1bdde89ffc..4af608a61cd9 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -689,10 +689,22 @@ struct devfreq *devfreq_add_device(struct device *dev,
devfreq->profile->max_state,
devfreq->profile->max_state),
GFP_KERNEL);
+ if (!devfreq->trans_table) {
+ mutex_unlock(&devfreq->lock);
+ err = -ENOMEM;
+ goto err_devfreq;
+ }
+
devfreq->time_in_state = devm_kcalloc(&devfreq->dev,
devfreq->profile->max_state,
sizeof(unsigned long),
GFP_KERNEL);
+ if (!devfreq->time_in_state) {
+ mutex_unlock(&devfreq->lock);
+ err = -ENOMEM;
+ goto err_devfreq;
+ }
+
devfreq->last_stat_updated = jiffies;
srcu_init_notifier_head(&devfreq->transition_notifier_list);
@@ -726,7 +738,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
err_init:
mutex_unlock(&devfreq_list_lock);
-
+err_devfreq:
devfreq_remove_device(devfreq);
devfreq = NULL;
err_dev: