Skip to content

Commit b466a59

Browse files
committed
powercap: call put_device() on an error path in powercap_register_control_type()
JIRA: https://issues.redhat.com/browse/RHEL-47408 commit 93c66fb Author: Joe Hattori <[email protected]> Date: Fri Jan 10 10:05:54 2025 +0900 powercap: call put_device() on an error path in powercap_register_control_type() powercap_register_control_type() calls device_register(), but does not release the refcount of the device when it fails. Call put_device() before returning an error to balance the refcount. Since the kfree(control_type) will be done by powercap_release(), remove the lines in powercap_register_control_type() before returning the error. This bug was found by an experimental verifier that I am developing. Signed-off-by: Joe Hattori <[email protected]> Link: https://patch.msgid.link/[email protected] [ rjw: Changelog edits ] Signed-off-by: Rafael J. Wysocki <[email protected]> Signed-off-by: David Arcari <[email protected]>
1 parent ddd3653 commit b466a59

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/powercap/powercap_sys.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,7 @@ struct powercap_control_type *powercap_register_control_type(
627627
dev_set_name(&control_type->dev, "%s", name);
628628
result = device_register(&control_type->dev);
629629
if (result) {
630-
if (control_type->allocated)
631-
kfree(control_type);
630+
put_device(&control_type->dev);
632631
return ERR_PTR(result);
633632
}
634633
idr_init(&control_type->idr);

0 commit comments

Comments
 (0)