]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
powercap: fix race condition in register_control_type()
authorSumeet Pawnikar <sumeet4linux@gmail.com>
Fri, 5 Dec 2025 19:02:16 +0000 (00:32 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jan 2026 12:12:11 +0000 (13:12 +0100)
commitccde2b7ac39635565201da2970e8a47c0edc009c
tree5b4c12f8475abf5270f6fb0d9b0c92ae3695c126
parentca97360860eb02e3ae4ba42c19b439a0fcecbf06
powercap: fix race condition in register_control_type()

[ Upstream commit 7bda1910c4bccd4b8d4726620bb3d6bbfb62286e ]

The device becomes visible to userspace via device_register()
even before it fully initialized by idr_init(). If userspace
or another thread tries to register a zone immediately after
device_register(), the control_type_valid() will fail because
the control_type is not yet in the list. The IDR is not yet
initialized, so this race condition causes zone registration
failure.

Move idr_init() and list addition before device_register()
fix the race condition.

Signed-off-by: Sumeet Pawnikar <sumeet4linux@gmail.com>
[ rjw: Subject adjustment, empty line added ]
Link: https://patch.msgid.link/20251205190216.5032-1-sumeet4linux@gmail.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/powercap/powercap_sys.c