public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] FMC: NULL dereference on allocation failure
@ 2013-06-19 14:49 Dan Carpenter
  2013-06-19 15:25 ` Alessandro Rubini
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2013-06-19 14:49 UTC (permalink / raw)
  To: Alessandro Rubini; +Cc: linux-kernel, kernel-janitors

If we don't allocate "arr" then the cleanup path will dereference it and
oops.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/fmc/fmc-sdb.c b/drivers/fmc/fmc-sdb.c
index 74fb326..79adc39 100644
--- a/drivers/fmc/fmc-sdb.c
+++ b/drivers/fmc/fmc-sdb.c
@@ -46,16 +46,17 @@ static struct sdb_array *__fmc_scan_sdb_tree(struct fmc_device *fmc,
 	onew = __sdb_rd(fmc, sdb_addr + 4, convert);
 	n = __be16_to_cpu(*(uint16_t *)&onew);
 	arr = kzalloc(sizeof(*arr), GFP_KERNEL);
-	if (arr) {
-		arr->record = kzalloc(sizeof(arr->record[0]) * n, GFP_KERNEL);
-		arr->subtree = kzalloc(sizeof(arr->subtree[0]) * n, GFP_KERNEL);
-	}
-	if (!arr || !arr->record || !arr->subtree) {
+	if (!arr)
+		return ERR_PTR(-ENOMEM);
+	arr->record = kzalloc(sizeof(arr->record[0]) * n, GFP_KERNEL);
+	arr->subtree = kzalloc(sizeof(arr->subtree[0]) * n, GFP_KERNEL);
+	if (!arr->record || !arr->subtree) {
 		kfree(arr->record);
 		kfree(arr->subtree);
 		kfree(arr);
 		return ERR_PTR(-ENOMEM);
 	}
+
 	arr->len = n;
 	arr->level = level;
 	arr->fmc = fmc;

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

end of thread, other threads:[~2013-06-20  8:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-19 14:49 [patch] FMC: NULL dereference on allocation failure Dan Carpenter
2013-06-19 15:25 ` Alessandro Rubini
2013-06-19 15:57   ` Dan Carpenter
2013-06-19 16:01     ` [patch -next] " Dan Carpenter
2013-06-19 16:15       ` Joe Perches
2013-06-19 17:57         ` Alessandro Rubini
2013-06-19 18:09           ` Joe Perches
2013-06-20  8:06           ` Dan Carpenter
2013-06-19 17:57     ` [patch] " Alessandro Rubini

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