Commit cccf671b authored by Qiushi Wu's avatar Qiushi Wu Committed by Khalid Elmously

cpuidle: Fix three reference count leaks

BugLink: https://bugs.launchpad.net/bugs/1884564

[ Upstream commit c343bf1b ]

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 "b8eb7183" fixed a similar problem.
Signed-off-by: default avatarQiushi Wu <wu000273@umn.edu>
[ rjw: Subject ]
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent f4f2bb24
...@@ -412,7 +412,7 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device) ...@@ -412,7 +412,7 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle, ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle,
&kdev->kobj, "state%d", i); &kdev->kobj, "state%d", i);
if (ret) { if (ret) {
kfree(kobj); kobject_put(&kobj->kobj);
goto error_state; goto error_state;
} }
kobject_uevent(&kobj->kobj, KOBJ_ADD); kobject_uevent(&kobj->kobj, KOBJ_ADD);
...@@ -542,7 +542,7 @@ static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev) ...@@ -542,7 +542,7 @@ static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
ret = kobject_init_and_add(&kdrv->kobj, &ktype_driver_cpuidle, ret = kobject_init_and_add(&kdrv->kobj, &ktype_driver_cpuidle,
&kdev->kobj, "driver"); &kdev->kobj, "driver");
if (ret) { if (ret) {
kfree(kdrv); kobject_put(&kdrv->kobj);
return ret; return ret;
} }
...@@ -636,7 +636,7 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev) ...@@ -636,7 +636,7 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev)
error = kobject_init_and_add(&kdev->kobj, &ktype_cpuidle, &cpu_dev->kobj, error = kobject_init_and_add(&kdev->kobj, &ktype_cpuidle, &cpu_dev->kobj,
"cpuidle"); "cpuidle");
if (error) { if (error) {
kfree(kdev); kobject_put(&kdev->kobj);
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment