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)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 20 Jul 2023 18:27:10 +0000 (20:27 +0200)
commit3e767d6850f867cc33ac16ca097350a1d2417982
tree22999771715e0a85c2b3c3a76b00613e17cd16ca
parentfdf0eaf11452d72945af31804e2a1048ee1b574c
powercap: arm_scmi: Remove recursion while parsing zones

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>
drivers/powercap/arm_scmi_powercap.c