[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230320055751.4120251-1-qiang1.zhang@intel.com>
Date: Mon, 20 Mar 2023 13:57:51 +0800
From: Zqiang <qiang1.zhang@...el.com>
To: paulmck@...nel.org, frederic@...nel.org, joel@...lfernandes.org
Cc: rcu@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] srcu: Fix srcu structure's->srcu_sup memory leak in init_srcu_struct_fields()
When use init_srcu_struct() to initializing srcu structure, and
will allocate memory for srcu structure's->sda and ->srcu_sup,
however, if allocate srcu structure's->sda memory failed, the
srcu structure's->srcu_sup memory need to be released.
Signed-off-by: Zqiang <qiang1.zhang@...el.com>
---
kernel/rcu/srcutree.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index d86ff4eb015a..1fb078abbdc9 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -255,8 +255,11 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
ssp->srcu_sup->sda_is_static = is_static;
if (!is_static)
ssp->sda = alloc_percpu(struct srcu_data);
- if (!ssp->sda)
+ if (!ssp->sda) {
+ if (!is_static)
+ kfree(ssp->srcu_sup);
return -ENOMEM;
+ }
init_srcu_struct_data(ssp);
ssp->srcu_sup->srcu_gp_seq_needed_exp = 0;
ssp->srcu_sup->srcu_last_gp_end = ktime_get_mono_fast_ns();
@@ -265,6 +268,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
if (!ssp->srcu_sup->sda_is_static) {
free_percpu(ssp->sda);
ssp->sda = NULL;
+ kfree(ssp->srcu_sup);
return -ENOMEM;
}
} else {
--
2.25.1
Powered by blists - more mailing lists