Skip to content

Commit

Permalink
powercap: call put_device() on an error path in powercap_register_con…
Browse files Browse the repository at this point in the history
…trol_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 <joe@pf.is.s.u-tokyo.ac.jp>
Link: https://patch.msgid.link/20250110010554.1583411-1-joe@pf.is.s.u-tokyo.ac.jp
[ rjw: Changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Joe Hattori authored and Rafael J. Wysocki committed Jan 23, 2025
1 parent f4b9d3b commit 93c66fb
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/powercap/powercap_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,7 @@ struct powercap_control_type *powercap_register_control_type(
dev_set_name(&control_type->dev, "%s", name);
result = device_register(&control_type->dev);
if (result) {
if (control_type->allocated)
kfree(control_type);
put_device(&control_type->dev);
return ERR_PTR(result);
}
idr_init(&control_type->idr);
Expand Down

0 comments on commit 93c66fb

Please sign in to comment.