From: Dan Carpenter <dan.carpenter@oracle.com>
To: Alessandro Rubini <rubini@gnudd.com>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [patch] FMC: NULL dereference on allocation failure
Date: Wed, 19 Jun 2013 14:49:04 +0000 [thread overview]
Message-ID: <20130619144904.GA10484@elgon.mountain> (raw)
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;
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Alessandro Rubini <rubini@gnudd.com>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [patch] FMC: NULL dereference on allocation failure
Date: Wed, 19 Jun 2013 17:49:04 +0300 [thread overview]
Message-ID: <20130619144904.GA10484@elgon.mountain> (raw)
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;
next reply other threads:[~2013-06-19 14:49 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-19 14:49 Dan Carpenter [this message]
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:25 ` Alessandro Rubini
2013-06-19 15:57 ` Dan Carpenter
2013-06-19 15:57 ` Dan Carpenter
2013-06-19 16:01 ` [patch -next] " Dan Carpenter
2013-06-19 16:01 ` Dan Carpenter
2013-06-19 16:15 ` Joe Perches
2013-06-19 16:15 ` Joe Perches
2013-06-19 17:57 ` Alessandro Rubini
2013-06-19 17:57 ` Alessandro Rubini
2013-06-19 18:09 ` Joe Perches
2013-06-19 18:09 ` Joe Perches
2013-06-20 8:06 ` Dan Carpenter
2013-06-20 8:06 ` Dan Carpenter
2013-06-19 17:57 ` [patch] " Alessandro Rubini
2013-06-19 17:57 ` Alessandro Rubini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130619144904.GA10484@elgon.mountain \
--to=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rubini@gnudd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.