Commit e5f5a66c authored by Anel Orazgaliyeva's avatar Anel Orazgaliyeva Committed by Rafael J. Wysocki

cpuidle: Fix kobject memory leaks in error paths

Commit c343bf1b ("cpuidle: Fix three reference count leaks")
fixes the cleanup of kobjects; however, it removes kfree() calls
altogether, leading to memory leaks.

Fix those and also defer the initialization of dev->kobj_dev until
after the error check, so that we do not end up with a dangling
pointer.

Fixes: c343bf1b ("cpuidle: Fix three reference count leaks")
Signed-off-by: default avatarAnel Orazgaliyeva <anelkz@amazon.de>
Suggested-by: default avatarAman Priyadarshi <apeureka@amazon.de>
[ rjw: Subject edits ]
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent c227233a
...@@ -488,6 +488,7 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device) ...@@ -488,6 +488,7 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
&kdev->kobj, "state%d", i); &kdev->kobj, "state%d", i);
if (ret) { if (ret) {
kobject_put(&kobj->kobj); kobject_put(&kobj->kobj);
kfree(kobj);
goto error_state; goto error_state;
} }
cpuidle_add_s2idle_attr_group(kobj); cpuidle_add_s2idle_attr_group(kobj);
...@@ -619,6 +620,7 @@ static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev) ...@@ -619,6 +620,7 @@ static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
&kdev->kobj, "driver"); &kdev->kobj, "driver");
if (ret) { if (ret) {
kobject_put(&kdrv->kobj); kobject_put(&kdrv->kobj);
kfree(kdrv);
return ret; return ret;
} }
...@@ -705,7 +707,6 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev) ...@@ -705,7 +707,6 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev)
if (!kdev) if (!kdev)
return -ENOMEM; return -ENOMEM;
kdev->dev = dev; kdev->dev = dev;
dev->kobj_dev = kdev;
init_completion(&kdev->kobj_unregister); init_completion(&kdev->kobj_unregister);
...@@ -713,9 +714,11 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev) ...@@ -713,9 +714,11 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev)
"cpuidle"); "cpuidle");
if (error) { if (error) {
kobject_put(&kdev->kobj); kobject_put(&kdev->kobj);
kfree(kdev);
return error; return error;
} }
dev->kobj_dev = kdev;
kobject_uevent(&kdev->kobj, KOBJ_ADD); kobject_uevent(&kdev->kobj, KOBJ_ADD);
return 0; return 0;
......
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