]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
powercap: call put_device() on an error path in powercap_register_control_type()
authorJoe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Fri, 10 Jan 2025 01:05:54 +0000 (10:05 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Apr 2025 12:31:50 +0000 (14:31 +0200)
commit4a2ea3dd4eb99a5deedcb10100399b7300b0a54c
treeb265efc4d87f14ec88c9319da483ef873880b89b
parent54595d6e8b6ffde7058cc1a5a3f731172e7edfdb
powercap: call put_device() on an error path in powercap_register_control_type()

[ Upstream commit 93c66fbc280747ea700bd6199633d661e3c819b3 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/powercap/powercap_sys.c