* [PATCH 0/3] SCMI Powercap zones processing fixes
@ 2026-11-15 11:05 Cristian Marussi
2026-11-15 11:05 ` [PATCH 1/3] powercap: arm_scmi: Fix potential stale zones after a skipped leaf Cristian Marussi
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Cristian Marussi @ 2026-11-15 11:05 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, linux-pm, arm-scmi
Cc: sudeep.holla, philip.radford, Cristian Marussi
Hi,
A tiny series of fixes around SCMI Powercap hierarchy-scanning logic to
address a number of issues reported by Sashiko.
Patch 1/2 is really a repost to an alreday reviewed fix, included here
simply to avoid conflicts.
Patch 2/3 provides the fixes around the logic used by the SCMI Powercap
driver to validate the hierarchy of zones provided by the SCMI platform
firmware: these are applied first to the original code to ease
backporting.
Patch 3/3 simplifies the code above by refactoring using cleanup handlers.
Based on v7.4-rc2.
Thanks,
Cristian
Cristian Marussi (2):
powercap: arm_scmi: Reject zones hierarchy containing cycles or holes
powercap: arm_scmi: Refactor scmi_zones_register error path
Guangshuo Li (1):
powercap: arm_scmi: Fix potential stale zones after a skipped leaf
drivers/powercap/arm_scmi_powercap.c | 42 +++++++++++++++++++---------
1 file changed, 29 insertions(+), 13 deletions(-)
--
2.54.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] powercap: arm_scmi: Fix potential stale zones after a skipped leaf
2026-11-15 11:05 [PATCH 0/3] SCMI Powercap zones processing fixes Cristian Marussi
@ 2026-11-15 11:05 ` Cristian Marussi
2026-11-16 15:25 ` Sudeep Holla
2026-11-15 11:05 ` [PATCH 2/3] powercap: arm_scmi: Reject zones hierarchy containing cycles or holes Cristian Marussi
2026-11-15 11:05 ` [PATCH 3/3] powercap: arm_scmi: Refactor scmi_zones_register error path Cristian Marussi
2 siblings, 1 reply; 7+ messages in thread
From: Cristian Marussi @ 2026-11-15 11:05 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, linux-pm, arm-scmi
Cc: sudeep.holla, philip.radford, Guangshuo Li, Rafael J. Wysocki,
stable, Cristian Marussi
From: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
scmi_zones_register() skips leaf zones that cannot be registered, but
returns the last leaf error when that leaf ends the traversal. Probe
then fails without unregistering the successfully registered zones,
whose private data is device-managed.
Return success after completing the traversal. Keep the existing error
return and full rollback for a failed non-leaf zone.
This issue was found by our static analysis tool under development.
Fixes: 3e767d6850f8 ("powercap: arm_scmi: Remove recursion while parsing zones")
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
drivers/powercap/arm_scmi_powercap.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/powercap/arm_scmi_powercap.c b/drivers/powercap/arm_scmi_powercap.c
index 63a956cf8d2b..e2270476a98c 100644
--- a/drivers/powercap/arm_scmi_powercap.c
+++ b/drivers/powercap/arm_scmi_powercap.c
@@ -407,6 +407,7 @@ static int scmi_zones_register(struct device *dev,
node);
}
}
+ ret = 0;
out:
kfree(zones_stack);
--
2.54.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] powercap: arm_scmi: Reject zones hierarchy containing cycles or holes
2026-11-15 11:05 [PATCH 0/3] SCMI Powercap zones processing fixes Cristian Marussi
2026-11-15 11:05 ` [PATCH 1/3] powercap: arm_scmi: Fix potential stale zones after a skipped leaf Cristian Marussi
@ 2026-11-15 11:05 ` Cristian Marussi
2026-11-16 15:26 ` Sudeep Holla
2026-11-15 11:05 ` [PATCH 3/3] powercap: arm_scmi: Refactor scmi_zones_register error path Cristian Marussi
2 siblings, 1 reply; 7+ messages in thread
From: Cristian Marussi @ 2026-11-15 11:05 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, linux-pm, arm-scmi
Cc: sudeep.holla, philip.radford, Cristian Marussi, Sashiko,
Rafael J. Wysocki
While walking the hierarchy of powercap zones received from the SCMI server
bailout with an error if any cycle or hole is detected in the received set
of zones which has to represent a tree or a forest.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-6466cd8d-c2b1-43da-8141-bf8bf49a17b1
Closes: https://sashiko.dev/#/bug/linux-4895c0ac-74f4-4860-a006-9f5ef7b0a012
Fixes: 3e767d6850f8 ("powercap: arm_scmi: Remove recursion while parsing zones")
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
drivers/powercap/arm_scmi_powercap.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/drivers/powercap/arm_scmi_powercap.c b/drivers/powercap/arm_scmi_powercap.c
index e2270476a98c..dbc9871fc1e2 100644
--- a/drivers/powercap/arm_scmi_powercap.c
+++ b/drivers/powercap/arm_scmi_powercap.c
@@ -22,6 +22,7 @@ static const struct scmi_powercap_proto_ops *powercap_ops;
struct scmi_powercap_zone {
bool registered;
bool invalid;
+ bool visited;
unsigned int height;
struct device *dev;
struct scmi_protocol_handle *ph;
@@ -316,6 +317,7 @@ static int scmi_powercap_register_zone(struct scmi_powercap_root *pr,
spz->info->name, parent ? parent->info->name : "ROOT",
spz->height);
} else {
+ spz->invalid = true;
list_del(&spz->node);
ret = PTR_ERR(z);
dev_err(spz->dev,
@@ -379,8 +381,25 @@ static int scmi_zones_register(struct device *dev,
while (spz) {
struct scmi_powercap_zone *parent;
+ spz->visited = true;
parent = scmi_powercap_get_parent_zone(spz);
if (parent && !parent->registered) {
+ /*
+ * An un-registered parent node is never visited twice:
+ * when that happens it is either a cycle or a hole, i.e.
+ * the attempt to walk again through a node which was already
+ * removed from @scmi_zones since it previously failed to
+ * register.
+ */
+ if (parent->visited) {
+ dev_err(dev, "Found a %s in zone ID %u\n",
+ parent->invalid ? "hole" : "cycle",
+ parent->info->id);
+ scmi_powercap_unregister_all_zones(pr);
+ ret = -EINVAL;
+ reg_zones = 0;
+ goto out;
+ }
zones_stack[sp++] = spz;
spz = parent;
} else {
@@ -392,8 +411,8 @@ static int scmi_zones_register(struct device *dev,
* Bail-out.
*/
dev_err(dev,
- "Failed to register non-leaf zone - ret:%d\n",
- ret);
+ "Failed to register non-leaf zone ID %u - ret:%d\n",
+ spz->info->id, ret);
scmi_powercap_unregister_all_zones(pr);
reg_zones = 0;
goto out;
--
2.54.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] powercap: arm_scmi: Refactor scmi_zones_register error path
2026-11-15 11:05 [PATCH 0/3] SCMI Powercap zones processing fixes Cristian Marussi
2026-11-15 11:05 ` [PATCH 1/3] powercap: arm_scmi: Fix potential stale zones after a skipped leaf Cristian Marussi
2026-11-15 11:05 ` [PATCH 2/3] powercap: arm_scmi: Reject zones hierarchy containing cycles or holes Cristian Marussi
@ 2026-11-15 11:05 ` Cristian Marussi
2026-11-16 15:24 ` Sudeep Holla
2 siblings, 1 reply; 7+ messages in thread
From: Cristian Marussi @ 2026-11-15 11:05 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, linux-pm, arm-scmi
Cc: sudeep.holla, philip.radford, Cristian Marussi, Rafael J. Wysocki
Refactor and simplify scmi_zones_register error path by using
cleanup handlers.
No functional change.
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
drivers/powercap/arm_scmi_powercap.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/drivers/powercap/arm_scmi_powercap.c b/drivers/powercap/arm_scmi_powercap.c
index dbc9871fc1e2..6346037c889d 100644
--- a/drivers/powercap/arm_scmi_powercap.c
+++ b/drivers/powercap/arm_scmi_powercap.c
@@ -5,6 +5,7 @@
* Copyright (C) 2022 ARM Ltd.
*/
+#include <linux/cleanup.h>
#include <linux/device.h>
#include <linux/math.h>
#include <linux/limits.h>
@@ -368,11 +369,12 @@ static int scmi_powercap_register_zone(struct scmi_powercap_root *pr,
static int scmi_zones_register(struct device *dev,
struct scmi_powercap_root *pr)
{
- int ret = 0;
unsigned int sp = 0, reg_zones = 0;
- struct scmi_powercap_zone *spz, **zones_stack;
+ struct scmi_powercap_zone *spz;
+ int ret = 0;
- zones_stack = kzalloc_objs(spz, pr->num_zones);
+ struct scmi_powercap_zone **zones_stack __free(kfree) =
+ kzalloc_objs(spz, pr->num_zones);
if (!zones_stack)
return -ENOMEM;
@@ -396,9 +398,7 @@ static int scmi_zones_register(struct device *dev,
parent->invalid ? "hole" : "cycle",
parent->info->id);
scmi_powercap_unregister_all_zones(pr);
- ret = -EINVAL;
- reg_zones = 0;
- goto out;
+ return -EINVAL;
}
zones_stack[sp++] = spz;
spz = parent;
@@ -407,16 +407,14 @@ static int scmi_zones_register(struct device *dev,
if (!ret) {
reg_zones++;
} else if (sp) {
- /* Failed to register a non-leaf zone.
- * Bail-out.
- */
+ /* Failed to register a non-leaf zone. Bail-out. */
dev_err(dev,
"Failed to register non-leaf zone ID %u - ret:%d\n",
spz->info->id, ret);
scmi_powercap_unregister_all_zones(pr);
- reg_zones = 0;
- goto out;
+ return ret;
}
+
/* Pick next zone to process */
if (sp)
spz = zones_stack[--sp];
@@ -426,13 +424,11 @@ static int scmi_zones_register(struct device *dev,
node);
}
}
- ret = 0;
-out:
- kfree(zones_stack);
+ /* If we get here any previous error was on a leaf zone, so ignored */
dev_info(dev, "Registered %d SCMI Powercap domains !\n", reg_zones);
- return ret;
+ return 0;
}
static int scmi_powercap_probe(struct scmi_device *sdev)
--
2.54.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] powercap: arm_scmi: Refactor scmi_zones_register error path
2026-11-15 11:05 ` [PATCH 3/3] powercap: arm_scmi: Refactor scmi_zones_register error path Cristian Marussi
@ 2026-11-16 15:24 ` Sudeep Holla
0 siblings, 0 replies; 7+ messages in thread
From: Sudeep Holla @ 2026-11-16 15:24 UTC (permalink / raw)
To: Cristian Marussi, Rafael J. Wysocki
Cc: linux-kernel, linux-arm-kernel, Sudeep Holla, linux-pm, arm-scmi,
philip.radford
On Sun, Nov 15, 2026 at 11:05:46AM +0000, Cristian Marussi wrote:
> Refactor and simplify scmi_zones_register error path by using
> cleanup handlers.
>
> No functional change.
>
Reviewed-by: Sudeep Holla <sudeep.holla@kernel.org>
Hi Rafael,
Can you pick up 1/3 and 2/3 as fix for v7.4 and this refactoring for v7.5 ?
IIUC, the refactoring is done at last to keep fixes simple for backport.
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] powercap: arm_scmi: Fix potential stale zones after a skipped leaf
2026-11-15 11:05 ` [PATCH 1/3] powercap: arm_scmi: Fix potential stale zones after a skipped leaf Cristian Marussi
@ 2026-11-16 15:25 ` Sudeep Holla
0 siblings, 0 replies; 7+ messages in thread
From: Sudeep Holla @ 2026-11-16 15:25 UTC (permalink / raw)
To: Cristian Marussi
Cc: linux-kernel, linux-arm-kernel, linux-pm, arm-scmi,
philip.radford, Guangshuo Li, Rafael J. Wysocki, stable
On Sun, Nov 15, 2026 at 11:05:44AM +0000, Cristian Marussi wrote:
> From: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
>
> scmi_zones_register() skips leaf zones that cannot be registered, but
> returns the last leaf error when that leaf ends the traversal. Probe
> then fails without unregistering the successfully registered zones,
> whose private data is device-managed.
>
> Return success after completing the traversal. Keep the existing error
> return and full rollback for a failed non-leaf zone.
>
> This issue was found by our static analysis tool under development.
>
> Fixes: 3e767d6850f8 ("powercap: arm_scmi: Remove recursion while parsing zones")
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: stable@vger.kernel.org
Reviewed-by: Sudeep Holla <sudeep.holla@kernel.org>
> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
> Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>
> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
I may be wrong but sign-off when you repost means you are agreeing with
the change and hence review tag is not needed ?
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] powercap: arm_scmi: Reject zones hierarchy containing cycles or holes
2026-11-15 11:05 ` [PATCH 2/3] powercap: arm_scmi: Reject zones hierarchy containing cycles or holes Cristian Marussi
@ 2026-11-16 15:26 ` Sudeep Holla
0 siblings, 0 replies; 7+ messages in thread
From: Sudeep Holla @ 2026-11-16 15:26 UTC (permalink / raw)
To: Cristian Marussi
Cc: linux-kernel, linux-arm-kernel, Sudeep Holla, linux-pm, arm-scmi,
philip.radford, Sashiko, Rafael J. Wysocki
On Sun, Nov 15, 2026 at 11:05:45AM +0000, Cristian Marussi wrote:
> While walking the hierarchy of powercap zones received from the SCMI server
> bailout with an error if any cycle or hole is detected in the received set
> of zones which has to represent a tree or a forest.
>
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/bug/linux-6466cd8d-c2b1-43da-8141-bf8bf49a17b1
> Closes: https://sashiko.dev/#/bug/linux-4895c0ac-74f4-4860-a006-9f5ef7b0a012
> Fixes: 3e767d6850f8 ("powercap: arm_scmi: Remove recursion while parsing zones")
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Reviewed-by: Sudeep Holla <sudeep.holla@kernel.org>
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-16 15:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 11:05 [PATCH 0/3] SCMI Powercap zones processing fixes Cristian Marussi
2026-11-15 11:05 ` [PATCH 1/3] powercap: arm_scmi: Fix potential stale zones after a skipped leaf Cristian Marussi
2026-11-16 15:25 ` Sudeep Holla
2026-11-15 11:05 ` [PATCH 2/3] powercap: arm_scmi: Reject zones hierarchy containing cycles or holes Cristian Marussi
2026-11-16 15:26 ` Sudeep Holla
2026-11-15 11:05 ` [PATCH 3/3] powercap: arm_scmi: Refactor scmi_zones_register error path Cristian Marussi
2026-11-16 15:24 ` Sudeep Holla
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®