Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1496479 > unrolled thread

[PATCH 29/54] md/raid5: Return directly after a failed kcalloc() in alloc_thread_groups()

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2016-10-06 11:30 +0200
Last post2016-10-06 11:30 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 29/54] md/raid5: Return directly after a failed kcalloc() in  alloc_thread_groups() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-06 11:30 +0200

#1496479 — [PATCH 29/54] md/raid5: Return directly after a failed kcalloc() in alloc_thread_groups()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-06 11:30 +0200
Subject[PATCH 29/54] md/raid5: Return directly after a failed kcalloc() in alloc_thread_groups()
Message-ID<spda1-6DS-15@gated-at.bofh.it>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 5 Oct 2016 08:54:40 +0200

The kfree() function was called in up to two cases
by the alloc_thread_groups() function during error handling
even if the passed variable contained a null pointer.

* Return directly after a call of the kcalloc() function failed
  at the beginning.

* Simplify a condition check for memory allocation failures.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/md/raid5.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index b624ba6..d864871 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6265,10 +6265,12 @@ static int alloc_thread_groups(struct r5conf *conf, int cnt,
 	}
 	*group_cnt = num_possible_nodes();
 	workers = kcalloc(cnt * *group_cnt, sizeof(*workers), GFP_NOIO);
+	if (!workers)
+		return -ENOMEM;
+
 	*worker_groups = kcalloc(*group_cnt, sizeof(**worker_groups), GFP_NOIO);
-	if (!*worker_groups || !workers) {
+	if (!*worker_groups) {
 		kfree(workers);
-		kfree(*worker_groups);
 		return -ENOMEM;
 	}
 
-- 
2.10.1

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web