public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel/smp.c: free related resources when failure occurs in hotplug_cfd()
@ 2013-07-08  8:50 Chen Gang
  2013-07-08 14:26 ` Paul Gortmaker
  2013-07-09  0:28 ` Wang YanQing
  0 siblings, 2 replies; 8+ messages in thread
From: Chen Gang @ 2013-07-08  8:50 UTC (permalink / raw)
  To: Paul Gortmaker, lig.fnst, chuansheng.liu, Wang YanQing
  Cc: Andrew Morton, linux-kernel@vger.kernel.org

When failure occurs in hotplug_cfd(), need release related resources,
or will cause memory leak.

Also beautify the related code.

Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 kernel/smp.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/kernel/smp.c b/kernel/smp.c
index 02a885d..c264623 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -45,15 +45,20 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
 	switch (action) {
 	case CPU_UP_PREPARE:
 	case CPU_UP_PREPARE_FROZEN:
-		if (!zalloc_cpumask_var_node(&cfd->cpumask, GFP_KERNEL,
-				cpu_to_node(cpu)))
+		if (!zalloc_cpumask_var_node(&cfd->cpumask,
+						GFP_KERNEL, cpu_to_node(cpu)))
 			return notifier_from_errno(-ENOMEM);
-		if (!zalloc_cpumask_var_node(&cfd->cpumask_ipi, GFP_KERNEL,
-				cpu_to_node(cpu)))
+
+		if (!zalloc_cpumask_var_node(&cfd->cpumask_ipi,
+						GFP_KERNEL, cpu_to_node(cpu))) {
+			free_cpumask_var(cfd->cpumask);
 			return notifier_from_errno(-ENOMEM);
+		}
+
 		cfd->csd = alloc_percpu(struct call_single_data);
 		if (!cfd->csd) {
 			free_cpumask_var(cfd->cpumask);
+			free_cpumask_var(cfd->cpumask_ipi);
 			return notifier_from_errno(-ENOMEM);
 		}
 		break;
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-07-09  0:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-08  8:50 [PATCH] kernel/smp.c: free related resources when failure occurs in hotplug_cfd() Chen Gang
2013-07-08 14:26 ` Paul Gortmaker
2013-07-09  0:25   ` Chen Gang F T
2013-07-09  0:28 ` Wang YanQing
2013-07-09  0:32   ` Chen Gang
2013-07-09  0:43     ` [PATCH v2] " Chen Gang
2013-07-09  0:46       ` Wang YanQing
2013-07-09  0:46         ` Chen Gang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox