diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2013-06-19 12:01:01 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-06-19 23:30:31 -0400 |
commit | e42d50baf43120a78985f13f6e9c8f92fae091c2 (patch) | |
tree | e9f91f6a06afe1696be14092344cdececfe82e99 /drivers/fmc/fmc-sdb.c | |
parent | e3a3c3a205554e564751cd9c0276b2af813d7a92 (diff) |
FMC: NULL dereference on allocation failure
If we don't allocate "arr" then the cleanup path will dereference it and
oops.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/fmc/fmc-sdb.c')
-rw-r--r-- | drivers/fmc/fmc-sdb.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/drivers/fmc/fmc-sdb.c b/drivers/fmc/fmc-sdb.c index 74fb326f4af1..79adc39221ea 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, | |||
46 | onew = __sdb_rd(fmc, sdb_addr + 4, convert); | 46 | onew = __sdb_rd(fmc, sdb_addr + 4, convert); |
47 | n = __be16_to_cpu(*(uint16_t *)&onew); | 47 | n = __be16_to_cpu(*(uint16_t *)&onew); |
48 | arr = kzalloc(sizeof(*arr), GFP_KERNEL); | 48 | arr = kzalloc(sizeof(*arr), GFP_KERNEL); |
49 | if (arr) { | 49 | if (!arr) |
50 | arr->record = kzalloc(sizeof(arr->record[0]) * n, GFP_KERNEL); | 50 | return ERR_PTR(-ENOMEM); |
51 | arr->subtree = kzalloc(sizeof(arr->subtree[0]) * n, GFP_KERNEL); | 51 | arr->record = kzalloc(sizeof(arr->record[0]) * n, GFP_KERNEL); |
52 | } | 52 | arr->subtree = kzalloc(sizeof(arr->subtree[0]) * n, GFP_KERNEL); |
53 | if (!arr || !arr->record || !arr->subtree) { | 53 | if (!arr->record || !arr->subtree) { |
54 | kfree(arr->record); | 54 | kfree(arr->record); |
55 | kfree(arr->subtree); | 55 | kfree(arr->subtree); |
56 | kfree(arr); | 56 | kfree(arr); |
57 | return ERR_PTR(-ENOMEM); | 57 | return ERR_PTR(-ENOMEM); |
58 | } | 58 | } |
59 | |||
59 | arr->len = n; | 60 | arr->len = n; |
60 | arr->level = level; | 61 | arr->level = level; |
61 | arr->fmc = fmc; | 62 | arr->fmc = fmc; |