]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
powercap: arm_scmi: Remove recursion while parsing zones
authorCristian Marussi <cristian.marussi@arm.com>
Tue, 18 Jul 2023 10:17:26 +0000 (11:17 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:47:57 +0000 (09:47 +0200)
commitb427c23cebc5c926516f20304bf1acc05a33d147
treebd4a94073d1403c3923b3ef8429fa0738ac99c06
parentde1dbbefac85765bfe12c5fb198507ef603a7a58
powercap: arm_scmi: Remove recursion while parsing zones

[ Upstream commit 3e767d6850f867cc33ac16ca097350a1d2417982 ]

Powercap zones can be defined as arranged in a hierarchy of trees and when
registering a zone with powercap_register_zone(), the kernel powercap
subsystem expects this to happen starting from the root zones down to the
leaves; on the other side, de-registration by powercap_deregister_zone()
must begin from the leaf zones.

Available SCMI powercap zones are retrieved dynamically from the platform
at probe time and, while any defined hierarchy between the zones is
described properly in the zones descriptor, the platform returns the
availables zones with no particular well-defined order: as a consequence,
the trees possibly composing the hierarchy of zones have to be somehow
walked properly to register the retrieved zones from the root.

Currently the ARM SCMI Powercap driver walks the zones using a recursive
algorithm; this approach, even though correct and tested can lead to kernel
stack overflow when processing a returned hierarchy of zones composed by
particularly high trees.

Avoid possible kernel stack overflow by substituting the recursive approach
with an iterative one supported by a dynamically allocated stack-like data
structure.

Fixes: b55eef5226b7 ("powercap: arm_scmi: Add SCMI Powercap based driver")
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Acked-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/powercap/arm_scmi_powercap.c