tmigr_setup_groups() allocates 'stack' via kzalloc_objs(), but in the
case where WARN_ON_ONCE(i >= tmigr_hierarchy_levels) triggers, the
function returns -EINVAL without freeing 'stack', causing a memory leak.
Fix this by redirecting the error path to the common 'out:' label so
that 'stack' is properly freed.
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
kernel/time/timer_migration.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c
index 155eeaea4113..92bcf876630c 100644
--- a/kernel/time/timer_migration.c
+++ b/kernel/time/timer_migration.c
@@ -1804,8 +1804,10 @@ static int tmigr_setup_groups(unsigned int cpu, unsigned int node,
}
/* Assert single root without parent */
- if (WARN_ON_ONCE(i >= tmigr_hierarchy_levels))
- return -EINVAL;
+ if (WARN_ON_ONCE(i >= tmigr_hierarchy_levels)) {
+ err = -EINVAL;
+ goto out;
+ }
for (; i >= start_lvl; i--) {
group = stack[i];
--
2.43.0