Skip to content

Commit c343bf1

Browse files
QiushiWurafaeljw
authored andcommitted
cpuidle: Fix three reference count leaks
kobject_init_and_add() takes reference even when it fails. If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object. Previous commit "b8eb718348b8" fixed a similar problem. Signed-off-by: Qiushi Wu <[email protected]> [ rjw: Subject ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent a871be6 commit c343bf1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/cpuidle/sysfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
484484
ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle,
485485
&kdev->kobj, "state%d", i);
486486
if (ret) {
487-
kfree(kobj);
487+
kobject_put(&kobj->kobj);
488488
goto error_state;
489489
}
490490
cpuidle_add_s2idle_attr_group(kobj);
@@ -615,7 +615,7 @@ static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
615615
ret = kobject_init_and_add(&kdrv->kobj, &ktype_driver_cpuidle,
616616
&kdev->kobj, "driver");
617617
if (ret) {
618-
kfree(kdrv);
618+
kobject_put(&kdrv->kobj);
619619
return ret;
620620
}
621621

@@ -709,7 +709,7 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev)
709709
error = kobject_init_and_add(&kdev->kobj, &ktype_cpuidle, &cpu_dev->kobj,
710710
"cpuidle");
711711
if (error) {
712-
kfree(kdev);
712+
kobject_put(&kdev->kobj);
713713
return error;
714714
}
715715

0 commit comments

Comments
 (0)