summaryrefslogtreecommitdiffstats
path: root/drivers/cpuidle/sysfs.c
diff options
context:
space:
mode:
authorPan Bian <bianpan2016@163.com>2016-12-03 10:02:27 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-12-05 20:24:14 -0500
commit8f6040cebd2382a5cfb201419d40e7a4a193a412 (patch)
tree66bb6d61a0eae69f10ff0ce30bde5054957ef078 /drivers/cpuidle/sysfs.c
parentfb1013a01673acf7e94e38cda169828ac76b345a (diff)
cpuidle: fix improper return value on error
In function cpuidle_add_state_sysfs(), variable ret takes the return value. Its value should be negative on errors. Because ret is reset in the loop, its value will be 0 during the second and after repeat of the loop. If kzalloc() returns a NULL pointer then, it will return 0. It may be better to explicitly assign "-ENOMEM" when the call to kzalloc() fails. Link: https://bugzilla.kernel.org/show_bug.cgi?id=188901 Signed-off-by: Pan Bian <bianpan2016@163.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpuidle/sysfs.c')
-rw-r--r--drivers/cpuidle/sysfs.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index 832a2c3f01ff..c5adc8c9ac43 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -403,8 +403,10 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
403 /* state statistics */ 403 /* state statistics */
404 for (i = 0; i < drv->state_count; i++) { 404 for (i = 0; i < drv->state_count; i++) {
405 kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL); 405 kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL);
406 if (!kobj) 406 if (!kobj) {
407 ret = -ENOMEM;
407 goto error_state; 408 goto error_state;
409 }
408 kobj->state = &drv->states[i]; 410 kobj->state = &drv->states[i];
409 kobj->state_usage = &device->states_usage[i]; 411 kobj->state_usage = &device->states_usage[i];
410 init_completion(&kobj->kobj_unregister); 412 init_completion(&kobj->kobj_unregister);