[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20260204073337.57222-1-zhanxusheng@xiaomi.com>
Date: Wed, 4 Feb 2026 15:33:37 +0800
From: Zhan Xusheng <zhanxusheng1024@...il.com>
To: Frederic Weisbecker <frederic@...nel.org>
Cc: linux-kernel@...r.kernel.org,
Zhan Xusheng <zhanxusheng@...omi.com>
Subject: [PATCH] timers/migration: Improve error handling and resource cleanup in tmigr_setup_groups
Introduce a new helper function `tmigr_clean_groups` to centralize
cleanup of groups when an error occurs. This simplifies the error
handling and ensures consistent resource management. Additionally,
redundant error checks and resource freeing logic were removed.
Signed-off-by: Zhan Xusheng <zhanxusheng@...omi.com>
---
kernel/time/timer_migration.c | 37 +++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c
index 18dda1aa782d..a3b6b0af5900 100644
--- a/kernel/time/timer_migration.c
+++ b/kernel/time/timer_migration.c
@@ -1750,6 +1750,29 @@ static void tmigr_connect_child_parent(struct tmigr_group *child,
trace_tmigr_connect_child_parent(child);
}
+/**
+ * tmigr_clean_groups - Clean up groups in the given level range and free memory
+ * @stack: The stack holding groups
+ * @start_lvl: The starting level to clean from
+ * @end_lvl: The ending level to clean up to
+ *
+ * This function iterates over the stack from start_lvl to end_lvl and removes the
+ * groups from the list and frees the allocated memory. It is used to clean up
+ * groups when an error occurs.
+ */
+static void tmigr_clean_groups(struct tmigr_group **stack,
+ int start_lvl, int end_lvl)
+{
+ struct tmigr_group *group;
+ int i = end_lvl;
+
+ for (; i >= start_lvl; i--) {
+ group = stack[i];
+ list_del(&group->list);
+ kfree(group);
+ }
+}
+
static int tmigr_setup_groups(unsigned int cpu, unsigned int node,
struct tmigr_group *start, bool activate)
{
@@ -1774,7 +1797,10 @@ static int tmigr_setup_groups(unsigned int cpu, unsigned int node,
if (IS_ERR(group)) {
err = PTR_ERR(group);
i--;
- break;
+ /* Clean up already allocated groups. */
+ tmigr_clean_groups(stack, start_lvl, i);
+ /* Exit after cleanup. */
+ goto out;
}
top = i;
@@ -1803,12 +1829,6 @@ static int tmigr_setup_groups(unsigned int cpu, unsigned int node,
for (; i >= start_lvl; i--) {
group = stack[i];
- if (err < 0) {
- list_del(&group->list);
- kfree(group);
- continue;
- }
-
WARN_ON_ONCE(i != group->level);
/*
@@ -1832,9 +1852,6 @@ static int tmigr_setup_groups(unsigned int cpu, unsigned int node,
}
}
- if (err < 0)
- goto out;
-
if (activate) {
struct tmigr_walk data;
union tmigr_state state;
--
2.43.0
Powered by blists - more mailing lists